Php 获取最新的8项记录laravel 5.1
如何通过手机号码字段获取此查询的最新8张投票:Php 获取最新的8项记录laravel 5.1,php,mysql,laravel-5,Php,Mysql,Laravel 5,如何通过手机号码字段获取此查询的最新8张投票: results = DB::table('votes')->whereIn('votes.id', function($query){ $query->select(DB::raw('MAX(id) as id')) ->from('votes') ->groupBy('mobile_number', 'p
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将不包括在结果中
有什么想法吗?谢谢你试试这个
对于较旧的版本
take(8)->skip(8)->get();
对于新的版本
limit(8)->offset(8)->get();
试试这个
对于较旧的版本
take(8)->skip(8)->get();
对于新的版本
limit(8)->offset(8)->get();
使用这个
orderBy(?Query?->take(5)->get()
并不能得到结果,假设我有用户1和用户2,他们在同一位置上投票了10次,但候选人不同,所以目标是显示每个用户的投票,但仅限于最新的8次,因此,这意味着旧的投票不应该只包括显示中最新的8票。它不能通过这个orderBy(?Query?->take(5)->get()
来获得结果,假设我有用户1和用户2,他们在相同的位置上投票了10次,但不同的候选人,所以目标是显示每个用户的投票,但仅限于最新的8票,因此,这意味着旧的选票不应该只包括最新的8张。如果我是你,我会看雄辩,这将使查询变得更容易:-)如果我是你,我会看雄辩,这将使查询变得更容易:-)