Mysql laravel子查询,其中包含最大值和最大值

Mysql laravel子查询,其中包含最大值和最大值,mysql,laravel,Mysql,Laravel,我是laravel和mysql的新手 mysql查询是 按线程id从表组中选择maxid 我的桌子是空的 id thread_id 1 45a7 2 123c 3 45a7 4 d056 5 123c id thread_id 3 45a7 5 123c 4 d056 mysql表的输出为 id thread_id 1 45a7 2 123c 3 45a7 4 d056 5 123c id threa

我是laravel和mysql的新手

mysql查询是

按线程id从表组中选择maxid

我的桌子是空的

id  thread_id
1    45a7
2    123c
3    45a7
4    d056
5    123c
id   thread_id
3    45a7
5    123c
4    d056
mysql表的输出为

id  thread_id
1    45a7
2    123c
3    45a7
4    d056
5    123c
id   thread_id
3    45a7
5    123c
4    d056
在这里,我尝试将mysql查询传输到laravel,如下所示

模型::其中'id',函数$query{$query->groupBy'thread\u id'}->get


我做错了什么?

下面的内容应该与您的查询相匹配

Model::whereIn('id', function($query) { 
    $query->selectRaw('max(id)')->from('table')->groupBy('thread_id'); 
})->toSql();
这将输出

select * from "table" where "id" in (select max(id) from table group by "thread_id")