1

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?

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.