mysql查询到laravel 5

时间:2015-09-22 07:27:07

标签: laravel-5 eloquent

任何人都可以帮我将此查询转换为laravel 5:

SELECT `id`,`mobile_number`,`shortcode`,`chapter_id`,`message`
FROM tbl_votes 
WHERE id in (SELECT MAX(id) from tbl_votes GROUP BY `mobile_number`, position_id)

由于

1 个答案:

答案 0 :(得分:0)

搞清楚。感谢

DB::table('votes')->whereIn('id', function($query){
            $query->select(DB::raw('MAX(id) as id'))
                ->from('votes')
                ->groupBy('mobile_number', 'position_id');
        })->where(array('shortcode'=>$shortcode,'position_id'=>$positionId))->get();