0

我有这个 Subselect 查询,我希望能够将其转换为 Eloquent 查询。有人可以帮忙吗?

$query = 'SELECT * FROM ( SELECT * FROM `visits` WHERE `exit` = 0 ORDER BY `updated_at` DESC ) visits GROUP BY `visits`.`session_id`';

谢谢

4

1 回答 1

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();
于 2013-06-21T20:32:36.263 回答