Level 53
I think this should work:
$result = \DB::table('histories')
->selectRaw('number, DATE(start), sum(duration), count(*), SUM(if(duration = 0, 1, 0)) AS comments')
->groupBy(\DB::raw('number, DATE(start)'));
dd($result);
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi all,
I'm trying to convert a MySQL query to an Eloquent query but I can't find the right answer.
select number,DATE(start),sum(duration),count(*),SUM(if(duration = 0, 1, 0)) AS comments from histories group by number,DATE(start);
Really appreciate any ideas.
I think this should work:
$result = \DB::table('histories')
->selectRaw('number, DATE(start), sum(duration), count(*), SUM(if(duration = 0, 1, 0)) AS comments')
->groupBy(\DB::raw('number, DATE(start)'));
dd($result);
Please or to participate in this conversation.