Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/07/2010, 09:01
Kilofafeure
 
Fecha de Ingreso: noviembre-2006
Mensajes: 117
Antigüedad: 17 años, 5 meses
Puntos: 0
Problema con consulta

Hola, estoy haciendo una consulta y tengo un problemilla, les explico. Tengo que obtener una comunidad autonoma con tantos contratos, mi problema es que tengo que hacerlo en 2 consultas y obtengo 2 veces cada comunidad con tantos contratos por cada una. Espero me puedan ayudar ya que llevo mucho rato con esto y no se me ocurre como solucionarlo. Gracias por adelantado.

Código:
select distinct L.HFSLAND_DES, count(c.id_cont) as "contratos"
from contrat c, acteur a, td_address_back ab, hfs_lands l, tu_province p
where C.ID_ACTR_CLIENT = a.id_actr
and a.ADRB_ID = AB.ADRB_ID (+)
and AB.PRV_VA_CD_FK = L.PRV_CD_FK (+)
and AB.PRV_VA_CD_FK = P.PRV_VA_CD (+)
and C.DT_DEB_CONT between to_date('01012008','DD/MM/YYYY') and to_date('31122008','DD/MM/YYYY')
and C.CT_ID_TLP = 'FNC'
group by L.HFSLAND_DES
union
select distinct L.HFSLAND_DES, count(c.id_cont) as "contratos"
from contrat c, ligne_de_credit lc, acteur a, td_address_back ab, hfs_lands l, tu_province p
where c.id_lc = lc.id_lc
and lc.id_actr = a.id_actr
and a.ADRB_ID = AB.ADRB_ID (+)
and AB.PRV_VA_CD_FK = L.PRV_CD_FK (+)
and AB.PRV_VA_CD_FK = P.PRV_VA_CD (+)
and C.DT_DEB_CONT between to_date('01012008','DD/MM/YYYY') and to_date('31122008','DD/MM/YYYY')
and C.CT_ID_TLP = 'WSL'
group by L.HFSLAND_DES
order by 1, 2
;
Funciona igual con el distinct que sin el...