我正在尝试在Laravel中进行查询,但无法正常工作。我使用POSTGRESQL
select extract(year from fecha_creacion) as anio, extract(month from fecha_creacion) as mes,
sum(case when tipo = 'entrada' then 1 else 0 end )
from documento
group by extract(year from fecha_creacion), extract(month from fecha_creacion)
order by anio, mes;
我也尝试了以下方法。
$data = DB::table('documento')
->selectRaw('year from fecha_creacion AS anio, month from fecha_creacion AS mes')
->sum(case when tipo = 'entrada' then 1 else 0 end )
->orderBy(anio, mes, DESC)
->get();
答案 0 :(得分:0)