我将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();

最佳答案

DB::table('scadenze')->whereIn('created_at', function($query) {
   $query->from('scadenze')
         ->groupBy('processo_id')
         ->select(DB::raw('max(created_at)');
})->get();

08-06 09:19