Reputation: 3213
I've got the following query
SELECT crm_presupuestos.fecha_alta,
crm_presupuestos.id_vendedor,
Sum(
`precio` * ( 100 - `crm_presupuestosdetalles`.`bonif` ) / 100 * `crm_presupuestosdetalles`.`cantidad`) AS LineaNeto
FROM crm_presupuestos
RIGHT JOIN crm_presupuestosdetalles
ON crm_presupuestos.id_presupuesto =
crm_presupuestosdetalles.id_presupuesto
GROUP BY crm_presupuestos.fecha_alta,
crm_presupuestos.id_vendedor
HAVING (( Date(( crm_presupuestos.fecha_alta )) = Curdate() ));
This works okay, but I need it to sum all the linea neto
of each ID_Vendedor
. Also, I need a total at the end of this. Could somebody show me how to do it?
Upvotes: 1
Views: 149
Reputation: 29051
Try this:
SELECT IFNULL(Fecha_Alta, 'Total') Fecha_Alta, ID_Vendedor, SUM(LineaNeto) LineaNeto
FROM (SELECT cp.Fecha_Alta, cp.ID_Vendedor, SUM(Precio * (100-cpd.Bonif)/100*cpd.Cantidad) AS LineaNeto
FROM CRM_PRESUPUESTOS cp
RIGHT JOIN CRM_PresupuestosDetalles cpd ON cp.ID_Presupuesto = cpd.ID_Presupuesto
GROUP BY cp.Fecha_Alta, cp.ID_Vendedor
HAVING DATE(cp.Fecha_Alta)=CURDATE()) A
GROUP BY ID_Vendedor WITH ROLLUP;
Upvotes: 1