我正在尝试获取 Laravel select 语句中返回的记录总和,但我似乎无法正确获取。
我的原话如下;
$results = DB::table('polls')->select('polls.id as poll_id', 'poll_votes.vote_count as vote_count', 'poll_options.id as poll_option_id')
->join('poll_options','polls.id','=','poll_options.poll_id')
->join('poll_votes', 'poll_options.id', '=', 'poll_votes.poll_option_id')
->where([['polls.status','=','1'], ['poll_options.status','=','1'],])
->get();
我尝试在该->select行的最后一个元素之后添加以下内容,但我不断收到错误消息;
DB::raw('sum(poll_votes.vote_count) total_votes')
任何帮助将不胜感激