我想将mysql查询转换为laravel查询。
MySQL的:
SELECT * FROM scadenze WHERE created_at IN(SELECT MAX(created_at) FROM scadenze GROUP BY processo_id)
Laravel(我收到错误,类stdClass的对象无法转换为字符串):
DB::table('scadenze')->whereIn('created_at', DB::select("( SELECT MAX(created_at) FROM scadenze GROUP BY processo_id )"))->get();
答案 0 :(得分:2)
DB::table('scadenze')->whereIn('created_at', function($query) {
$query->from('scadenze')
->groupBy('processo_id')
->select(DB::raw('max(created_at)');
})->get();
答案 1 :(得分:0)
试试这个:
DB::table('scadenze')
->whereRaw(DB::raw("created_at IN (SELECT MAX(created_at) FROM scadenze GROUP BY processo_id)"))
->get();
我希望这可以提供帮助!