我有这个Subselect查询,我希望能够转换为Eloquent查询。有人可以帮忙吗?
$query = 'SELECT * FROM ( SELECT * FROM `visits` WHERE `exit` = 0 ORDER BY `updated_at` DESC ) visits GROUP BY `visits`.`session_id`';
由于
答案 0 :(得分:1)
查询使用了连接:
Visit::select('visits.*')->
join(DB::raw('(SELECT * FROM `visits` WHERE `exit` = 0 ORDER BY `updated_at` DESC, `id` DESC) v2'), 'visits.id', '=', 'v2.id')->
groupBy('visits.session_id')->get();