我的代码似乎忽略了我找不到HR.NAME的条目。我如何得到"未找到"在现场" SENT BY"?另外,如果它没有找到HR.NAME,请包含该数据。
SELECT DISTINCT MA.MOPID "MOP #"
,MA.MOPNOTIFICATIONSENT "Sent Status"
,MA.MOPNOTIFICATIONSENTBY "Employee ID"
,MA.MOPNOTIFICATIONSENDAT "Date Sent"
,HR.NAME "SENT BY"
FROM MOPUSER.MOPACTIVITY MA ,HR@SECADMIN HR
WHERE TO_CHAR(MOPNOTIFICATIONSENDAT, 'YYYY-MM-DD') BETWEEN TO_CHAR(SYSDATE, 'YYYY-MM-DD') AND TO_CHAR(SYSDATE, 'YYYY-MM-DD')
AND HR.EMPID = SUBSTR(MA.MOPNOTIFICATIONSENTBY, 2, (LENGTH(MA.MOPNOTIFICATIONSENTBY) - 1))
答案 0 :(得分:1)
尝试将COALESCE
功能与left join
SELECT DISTINCT MA.MOPID "MOP #"
,MA.MOPNOTIFICATIONSENT "Sent Status"
,MA.MOPNOTIFICATIONSENTBY "Employee ID"
,MA.MOPNOTIFICATIONSENDAT "Date Sent"
,COALESCE(HR.NAME,'Not found') as "SENT BY"
FROM MOPUSER.MOPACTIVITY MA
left join HR@SECADMIN HR on HR.EMPID = SUBSTR(MA.MOPNOTIFICATIONSENTBY, 2, (LENGTH(MA.MOPNOTIFICATIONSENTBY) - 1))
WHERE TO_CHAR(MOPNOTIFICATIONSENDAT, 'YYYY-MM-DD') BETWEEN TO_CHAR(SYSDATE, 'YYYY-MM-DD') AND TO_CHAR(SYSDATE, 'YYYY-MM-DD')