Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个 Subselect 查询,我希望能够将其转换为 Eloquent 查询。有人可以帮忙吗?
$query = 'SELECT * FROM ( SELECT * FROM `visits` WHERE `exit` = 0 ORDER BY `updated_at` DESC ) visits GROUP BY `visits`.`session_id`';
谢谢
让查询与连接一起工作:
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();