我怎样才能在此查询最新的8票通过手机号码字段:获得最新的8条laravel 5.1
results = DB::table('votes')->whereIn('votes.id', function($query){
$query->select(DB::raw('MAX(id) as id'))
->from('votes')
->groupBy('mobile_number', 'position_id','code');
})->where(array('code'=>$code,'position_id'=>$positionId))->get();
此查询它获取用户的最新总票数但不限于:8 。
->where(array('code'=>$code,'position_id'=>$positionId))->take(8)->get(); //it seems this is not working
这里的样品台
id mobile_number code position_id
1 123123 1 1
2 123123 3 1
3 321212 2 2
4 123123 4 1
5 123123 5 1
6 123123 6 1
7 123123 7 1
8 123123 8 1
9 123123 9 1
10 123123 10 1
,如果我得到的123123票,将只能得到最新8等上表中的Id 1将不会包含在结果中。
有什么想法?由于
如果我是你,我会看口才它将使查询非常容易:-) – Anoxy