【发布时间】:2014-11-18 03:18:07
【问题描述】:
背景:对于一个 SPRIDEN_id,sprhold_hldd_code 可能有一个或多个值或 NO 值。
我需要选择 SP.SPRIDEN_ID、SP.SPRIDEN_LAST_NAME、SP.SPRIDEN_FIRST_NAME、SR.SHRDGMR_SEQ_NO、SR.SHRDGMR_PROGRAM
哪里 (sh.sprhold_hldd_code = 'RH') 不存在。
到目前为止,没有返回任何记录。
我发现如果我在 sh.sprhold_hldd_code = 'Z' 中放入一个不在可能值列表中的代码(例如 Z),那么它会返回结果。
DATA: (column names abbreviated)
SPRIDEN_ID SPRIDEN_LAST SPRIDEN_FIRST SHRDGMR_SEQ_NO SHRDGMR_PROGRAM sh.sprhold_hldd_code
100001 Smith Sue 1 ALHE RH
100001 Smith Sue 1 ALHE AA
100001 Smith Sue 1 ALHE BB
100005 Conners Tim 1 BUSN RH
100008 Occent Mary 1 MATH CC
100008 Occent Mary 1 MATH AA
Expected Results: Mary is the only record that does NOT have the RH code.
SPRIDEN_ID SPRIDEN_LAST_NAME SPRIDEN_FIRST_NAME SHRDGMR_SEQ_NO SHRDGMR_PROGRAM
100008 Occent Mary 1 MATH
但我没有收到任何结果。
CODE:
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
and not exists
(select sh.sprhold_pidm
from sprhold sh
where sh.sprhold_hldd_code = 'RH')
【问题讨论】:
标签: sql string oracle not-exists