我在MySQL中有一个查询
SELECT * FROM group_recordings WHERE id IN ( SELECT MAX(id) FROM group_recordings GROUP BY time_span )
在“IN”运算符中有一个子查询,我想在laravel eloquent中转换此查询,我有GroupRecording Model。任何人帮助我
答案 0 :(得分:0)
我认为这种查询的Laravel风格将是,
GroupRecording::whereIn('id', function($query) {
$query->selectRaw('MAX(id)')
->from('group_recordings')
->groupBy('time_span');
})
->where('time_span', '>', $recording->time_span)
->get();