I have a query that essentially should bring the total sales per day but I don't know what I'm doing wrong in the query that brings me all the sales without adding the days.
$ventasdia = DB::select('SELECT DATE_FORMAT(v.fecha_venta,"%d/%m/%Y") as dia, sum(v.monto) as totaldia from ventas v where v.id_estado_venta="2" group by v.fecha_venta order by
day(v.fecha_venta) desc limit 12');
This is what the query brings me:
As can be seen, the days are repeated and it does not add up per day.
CodePudding user response:
You need to GROUP BY dia
not by v.fecha_venta
.
If you group by v.fetch_venta it groups by the datetime and this is probably different for every row.