Ver Mensaje Individual
  #6  
Antiguo 06-05-2005
Avatar de hermes_32
hermes_32 hermes_32 is offline
Miembro
 
Registrado: jul 2003
Posts: 94
Reputación: 21
hermes_32 Va por buen camino
Código Delphi [-]
SELECT P.nombre AS Promo, CL.nombre AS Cliente, 
 (select sum(c1.monto) 
  from facturacion c1
  join promociones p1 on p1.id = c1.idpromo
  where c1.id = c.id
  and c1.idcliente = cl.id
  group by c1.id) as Monto_Pro,   <- total monto promociones

 (select sum(c2.monto / p2.Euros * p2.puntos) 
  from facturacion c2
  join promociones p2 on p2.id = c2.idpromo
  and c2.id = c.id
  and c2.idcliente = cl.id
  group by c2.id) as Puntos_Pro,   <- total puntos promociones

 (select sum(c3.monto) 
  from facturacion c3
  join promociones p3 on p3.id = c3.idpromo
  where c3.id = c.id
  and c3.idcliente = cl.id
  group by c3.id) as Monto_ProN,   <- total monto normales

 (select sum(c4.monto / p4.Euros * p4.puntos) 
  from facturacion c4
  join promociones p4 on p4.id = c4.idpromo
  and c4.id = c.id
  and c4.idcliente = cl.id
  group by c4.id) as Puntos_ProN,   <- total puntos normales

 (select sum(c5.monto) 
  from facturacion c5
  join promociones p5 on p5.id = c5.idpromo
  where c5.id = c.id
  and c5.idcliente = cl.id
  group by c5.id) as Monto_ProE,   <- total monto especiales

 (select sum(c6.monto / p6.Euros * p4.puntos) 
  from facturacion c6
  join promociones p6 on p6.id = c6.idpromo
  and c6.id = c.id
  and c6.idcliente = cl.id
  group by c6.id) as Puntos_ProE   <- total puntos especiales

FROM FACTURACION C
      INNER JOIN CLIENTE CL ON CL.id=C.idcliente
      GROUP BY CL.nombre
      ORDER BY CL.nombre

Prueba con esto tio. A ver si es lo que necesitas y funciona.

Un saludo.
Responder Con Cita