Ver Mensaje Individual
  #39  
Antiguo 09-09-2008
hach hach is offline
Miembro
 
Registrado: mar 2007
Ubicación: Bariloche, Argentina
Posts: 44
Reputación: 0
hach Va por buen camino
Ya va, ya va Caral

Cita:
Me canso y no me dais la solución, a ver si os apuráis.
Saludos
A pedido de Caral, aca va un aporte

Se me ocurre crear un view

Código SQL [-]
CREATE VIEW CLIENTES_VIEW(
    IDCLIENTE,
    MES,
    CONDICION,
    IMPORTE)
AS
select c.idcliente, c.mes, c.condicion, c.importe
from clientes c
where c.condicion is not null
union
select c.idcliente, c.mes
, (select c2.condicion from clientes c2 where c2.condicion is not null and c2.idcliente=c.idcliente and c2.mes=c.mes)
, c.importe
from clientes c
where  c.condicion is null
;

y despues hacer el select sobre el view


Código SQL [-]
select idcliente, mes, condicion, sum(importe)
from clientes_view
group by idcliente, mes, condicion
order by idcliente, mes


Saludos
Responder Con Cita