我有一个包含100000条记录的表格,我得到97000条记录,作为以下查询的一部分,如何获取剩余的30000条记录。我试过不等于'H.RESOURCE_ID <> SQ.CPNT_OG_ID'
但没有得到正确的数据?
SELECT H.pernr AS "STUD_ID",
SQ.CPNT_TYP_ID,
SQ.CPNT_ID,
TO_CHAR (SQ.REV_DTE, 'MON-DD-YYYY HH24:MI:SS') AS REV_DTE,
CASE --WAIVED
WHEN sq.CPNT_TYP_ID = 'VIDEO' AND enrollment_status = 'Complete'
THEN
'VIDEO-COMPLETE'
WHEN sq.CPNT_TYP_ID = 'VIDEO' AND enrollment_status <> 'Complete'
THEN
'VIDEO-WAIVED'
WHEN sq.CPNT_TYP_ID = 'CERTIFICATION'
AND enrollment_status = 'Complete'
THEN
'CERT-COMPLETE'
WHEN sq.CPNT_TYP_ID = 'CERTIFICATION'
AND enrollment_status <> 'Complete'
THEN
'CERT-WAIVED'
WHEN sq.CPNT_TYP_ID = 'CDOC' AND enrollment_status = 'Complete'
THEN
'CDOC-COMPLETE'
WHEN sq.CPNT_TYP_ID = 'CDOC' AND enrollment_status <> 'Complete'
THEN
'CDOC-WAIVED'
WHEN sq.CPNT_TYP_ID = 'ELEARNING'
AND enrollment_status = 'Complete'
THEN
'Elearning-COMPLETE-PASSED'
WHEN sq.CPNT_TYP_ID = 'ELEARNING'
AND enrollment_status <> 'Complete'
THEN
'Elearning-WAIVED'
ELSE
NULL
END
"CMPL_STAT_ID",
TO_CHAR (H.COMPLETION_DATE, 'MON-DD-YYYY HH24:MI:SS')
AS COMPLETION_DATE,
'RECORD_Admin'
AS "ESIG_MEANING_CODE_ID",
NULL AS "LST_UPD_USR",
sq.rev_num AS "REV_NUM",
'LEARNSHARE' AS "COMMENTS"
FROM ZB_USR_HISTORY_NEW H
JOIN
(SELECT DISTINCT CPNT_ID,
CPNT_TYP_ID,
CPNT_OG_ID,
REV_DTE,
REV_NUM,
CPNT_COURSE_NUM
FROM TBL_ZIM_ITEM_new
WHERE VALID = '1' AND app_id LIKE '%en-us%' OR LENGTH (app_id) < 9)
SQ
ON (H.RESOURCE_ID = SQ.CPNT_OG_ID);
答案 0 :(得分:0)
只需用LEFT JOIN替换JOIN即可。您可以在SQL中使用LEFT JOIN或RIGHT JOIN,以便获取不满足连接条件的记录。在不存在的行中选择的列将为NULL。