Я пытаюсь сгруппировать результаты по выбранному необработанному полю,
$daily_summaries=DB::table("ticket_transactions")
->join('stations', 'stations.id', '=', 'ticket_transactions.station_id')
->join('companies' ,'companies.id','=' ,'ticket_transactions.company_id')
->where(['company_id'=>$id])
->select('ticket_transactions.company_id' , 'companies.name',
DB::raw('LEFT(ticket_transactions.date_issued,10) AS day', 'COUNT(ticket_transactions.id) AS tickets_sold',
'SUM(fare) AS revenue')
)
->groupBy('day')
->orderBy('day DESC')->get();
return $daily_summaries;
, это мой sql, когда я запускаю его напрямую.
select `ticket_transactions`.`company_id`, `companies`.`name`, LEFT(ticket_transactions.date_issued,10) AS day
from `ticket_transactions`
inner join `stations` on `stations`.`id` = `ticket_transactions`.`station_id`
inner join `companies` on `companies`.`id` = `ticket_transactions`.`company_id`
where (`company_id` = 2) group by `day` order by day DESC
Результат