Tuesday, February 28, 2017

Query Builder summarize the field value depending on another field

I have some table my some table

I need select an group iformation from these, but a have some conditions:

  • Group results by date (day). Ideally when day start on 09.00 and finsh 09.00 (24hr)
  • Then i need summarize values field sum where 'satus_id' = 10 into new variable example 'TotalIn' and where status_id = 12 into variable example TotalOut
  • Give results on view (but this no problem)

How to do it? I write this, but i now this is wrong:

$statistic =   DB::connection('mysql2')->table('payout_transactions')
        ->selectRaw('*, DATE(date) as day')
        ->where('status_id', 12)
        ->selectRaw('SUM(sum) AS TotalIn')
        ->groupBy('day')
        ->get();




via Taras Bezdushnuy

Advertisement