Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/09/2007, 07:53
mcalmanovici
 
Fecha de Ingreso: septiembre-2007
Mensajes: 2
Antigüedad: 17 años, 5 meses
Puntos: 0
Problema cuando trato de hacer un not exists.

Hola gente:
realmente me estoy volviendo loco con esta consulta y por este motivo recurro a su ayuda.
Tengo la siguiente consulta:
Código:
SELECT distinct MO.ESN, MO.USUARIO 'ACCOUNT',  MO.CONTRATO 'CONTRACT',  MO.MATRICULA 'SHIP_CODE',  MO.BARCO 'SHIP', 
DATE_FORMAT(ur.MAX_FECHA,'%d/%m/%y %H:%i:%s')  'LAST_RECEIVED', 
round((UNIX_TIMESTAMP(date_add(sysdate(), INTERVAL 3 HOUR))-UNIX_TIMESTAMP(ur.MAX_FECHA))/3600,2) 'HOURS FROM LAST', MO.IMSI, 0 'FLAG_COLOR_SQL' 
from SN_LOC_MONPESAT MO, temp_ultimos_reportes_control ur 
where MO.IMSI = ur.IMSI and  MO.PRIVADO is null and date_add(max_fecha,INTERVAL 3 MONTH) >= sysdate() and 
not exists (select 1 from esn_en_puerto eep where MO.ESN = eep.esn and ur.MAX_FECHA = eep.fecha) and
not exists (select 1 from temp_ultimos_reportes_control turc, LOC_RECORDS lc,SN_LOC_MONPESAT SLM 
where turc.imsi = lc.imsi and turc.max_fecha = lc.fecha and SLM.imsi = turc.imsi and SLM.privado is null and date_add(max_fecha,INTERVAL 3 MONTH) >= sysdate() 
group by lc.esn,lc.latitud,lc.longitud,lc.fecha,turc.imsi
having count(*) >= 3)
Esta consulta no me esta trayendo lo que yo quiero.
Si la ejecuto sin "select 1 from temp_ultimos_reportes_control turc, LOC_RECORDS lc,SN_LOC_MONPESAT SLM
where turc.imsi = lc.imsi and turc.max_fecha = lc.fecha and SLM.imsi = turc.imsi and SLM.privado is null and date_add(max_fecha,INTERVAL 3 MONTH) >= sysdate() group by lc.esn,lc.latitud,lc.longitud,lc.fecha,turc.imsi
having count(*) >= 3" me trae un montón de registros.
Cuando ejecuto esa consulta que mostré recién me trae solo un registro (cosa que esta bien).
Ahora cuando la consulta la hago tal como la mostré arriba de todo lo que no me trae nada cuando me debería traer todos los registros menos los que están en el not exists!!... Alguno tiene idea si el mysql tiene problemas con poner group by y having en el not exists??.. o alguna solución posible..

Muchas gracias.
Mariano.