我有一个查询可以提取有关用户的信息。用户可能没有、一个或多个电话号码。我要做的是让用户最新的电话号码(由 seq 号码确定)加入到带有其他基本人口统计数据的查询中。我面临的问题是,如果我的子查询返回 null 并且用户没有出现在我的查询中。如何处理子查询中的空值以便仍然返回这些行?
SELECT SPRIDEN.SPRIDEN_ID AS Student_ID ,
saradap.SARADAP_APST_CODE ,
saradap.SARADAP_PIDM ,
spriden.spriden_first_name ,
spriden.spriden_last_name ,
saradap.saradap_program_1 ,
spraddr.SPRADDR_STREET_LINE1 ,
spraddr.spraddr_city ,
spraddr.spraddr_zip ,
spraddr.spraddr_stat_code ,
saradap.SARADAP_APPL_DATE ,
'Individual' AS Account_Name ,
saradap.SARADAP_CAMP_CODE ,
CONCAT(sprtele_phone_area, sprtele_phone_number) "Phone" ,
sprtele_tele_code ,
sorcont_ctyp_code ,
sorcont_contact_date ,
sorcont.sorcont_activity_date
FROM saradap
LEFT JOIN spriden ON saradap.saradap_pidm = spriden_pidm
LEFT JOIN spraddr ON saradap.saradap_pidm = spraddr.spraddr_pidm
LEFT JOIN sprtele ON saradap.saradap_pidm = sprtele.sprtele_pidm
LEFT JOIN sorcont ON saradap.saradap_pidm = sorcont.sorcont_pidm
WHERE spriden.spriden_change_ind IS NULL
AND ( saradap.SARADAP_CAMP_CODE = 'D'
OR saradap.SARADAP_CAMP_CODE = 'JD'
)
AND saradap.saradap_appl_date > SYSDATE - 15
AND spraddr.spraddr_seqno = ( SELECT MAX(spraddr.spraddr_seqno)
FROM spraddr
WHERE saradap.SARADAP_PIDM = spraddr.spraddr_pidm
)
AND sprtele_seqno = ( SELECT MAX(SPRTELE_SEQNO)
FROM SATURN.SPRTELE
WHERE sprtele_pidm = saradap.saradap_pidm
)