sql >> Base de Datos >  >> RDS >> Oracle

Oracle SQL - No existe - la cadena no existe en una lista de valores

Para obtener los datos que desea, recomendaría usar la agregación con un having cláusula:

Select SP.SPRIDEN_ID, SP.SPRIDEN_LAST_NAME, SP.SPRIDEN_FIRST_NAME, SR.SHRDGMR_SEQ_NO, 
       SR.SHRDGMR_PROGRAM
from spriden SP join
     SHRDGMR SR
     on SP.SPRIDEN_PIDM = SR.SHRDGMR_PIDM join
     SPRHOLD SH
     on sp.spriden_pidm = sh.sprhold_pidm
where SR.SHRDGMR_DEGS_CODE = 'PN' and
      SR.SHRDGMR_TERM_CODE_GRAD >= '201489' and
     sp.spriden_change_ind is NULL
group by SP.SPRIDEN_ID, SP.SPRIDEN_LAST_NAME, SP.SPRIDEN_FIRST_NAME, SR.SHRDGMR_SEQ_NO, 
         SR.SHRDGMR_PROGRAM
having sum(case when sh.sprhold_hldd_code = 'RH' then 1 else 0 end) = 0;

Tienes dos problemas con tu enfoque. La primera es que la subconsulta devuelve verdadero o falso y afecta a todas las filas de la consulta original. Realmente quieres una subconsulta correlacionada. Pero, incluso si lo hizo bien, estaría devolviendo filas duplicadas para Mary. Esto resuelve ambos problemas.