我有以下三个表:
CREATE TABLE USER_STATUS ("UID" varchar2(7), "STAT_ID" varchar2(11)) ;
INSERT ALL
INTO USER_STATUS ("UID", "STAT_ID") VALUES ('UID_001', 'STAT_ID_001')
INTO USER_STATUS ("UID", "STAT_ID") VALUES ('UID_001', NULL)
INTO USER_STATUS ("UID", "STAT_ID") VALUES ('UID_001', NULL)
INTO USER_STATUS ("UID", "STAT_ID") VALUES ('UID_002', 'STAT_ID_002')
INTO USER_STATUS ("UID", "STAT_ID") VALUES ('UID_002', NULL)
INTO USER_STATUS ("UID", "STAT_ID") VALUES ('UID_003', 'STAT_ID_003')
SELECT * FROM dual;
CREATE TABLE STATUS_LKUP ("LKUP_ID" varchar2(11), "STAT_CODE" varchar2(11), "STAT_ID" varchar2(11), "STATUS" varchar2(20));
INSERT ALL
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_001', 'ST_CODE_001', 'STAT_ID_001', 'Processing')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_002', 'ST_CODE_002', 'STAT_ID_001', 'Processing')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_003', 'ST_CODE_003', 'STAT_ID_001', 'Processing')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_004', 'ST_CODE_004', 'STAT_ID_001', 'Processing')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_005', 'ST_CODE_011', 'STAT_ID_001', 'Issue')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_006', 'ST_CODE_012', 'STAT_ID_001', 'Issue')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_007', 'ST_CODE_013', 'STAT_ID_001', 'Issue')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_008', 'ST_CODE_014', 'STAT_ID_001', 'Issue')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_009', 'ST_CODE_015', 'STAT_ID_001', 'Issue')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_010', 'ST_CODE_021', 'STAT_ID_001', 'Done')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_011', 'ST_CODE_022', 'STAT_ID_001', 'Done')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_012', 'ST_CODE_031', 'STAT_ID_001', 'Started')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_013', 'ST_CODE_032', 'STAT_ID_001', 'Started')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_014', 'ST_CODE_002', 'STAT_ID_002', 'Processing (Sent)')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_015', 'ST_CODE_004', 'STAT_ID_002', 'Processing (Waiting)')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_016', 'ST_CODE_014', 'STAT_ID_002', 'Issue in Prod')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_017', 'ST_CODE_012', 'STAT_ID_002', 'Issue in Prod')
INTO STATUS_LKUP ("LKUP_ID", "STAT_CODE", "STAT_ID", "STATUS") VALUES ('LKUP_ID_018', 'ST_CODE_021', 'STAT_ID_002', 'Done')
SELECT * FROM dual;
CREATE TABLE CORE ("CORE_ID" varchar2(11), "STAT_CODE" varchar2(11));
INSERT ALL
INTO CORE ("CORE_ID", "STAT_CODE") VALUES ('CORE_ID_001', 'ST_CODE_001')
INTO CORE ("CORE_ID", "STAT_CODE") VALUES ('CORE_ID_002', 'ST_CODE_012')
INTO CORE ("CORE_ID", "STAT_CODE") VALUES ('CORE_ID_003', 'ST_CODE_021')
INTO CORE ("CORE_ID", "STAT_CODE") VALUES ('CORE_ID_004', 'ST_CODE_012')
INTO CORE ("CORE_ID", "STAT_CODE") VALUES ('CORE_ID_005', 'ST_CODE_012')
INTO CORE ("CORE_ID", "STAT_CODE") VALUES ('CORE_ID_006', 'ST_CODE_021')
INTO CORE ("CORE_ID", "STAT_CODE") VALUES ('CORE_ID_007', 'ST_CODE_001')
INTO CORE ("CORE_ID", "STAT_CODE") VALUES ('CORE_ID_008', 'ST_CODE_003')
INTO CORE ("CORE_ID", "STAT_CODE") VALUES ('CORE_ID_009', 'ST_CODE_012')
INTO CORE ("CORE_ID", "STAT_CODE") VALUES ('CORE_ID_010', 'ST_CODE_021')
INTO CORE ("CORE_ID", "STAT_CODE") VALUES ('CORE_ID_011', 'ST_CODE_001')
INTO CORE ("CORE_ID", "STAT_CODE") VALUES ('CORE_ID_013', 'ST_CODE_004')
SELECT * FROM dual;
请查看 -> Oracle SQL Fiddle
表已在 Oracle 数据库中创建。现在根据用户传递的 UID,我需要按如下方式检索他们的核心和状态:
到目前为止,我尝试检索结果,但无法将它们连接起来。
SELECT STLK.STAT_CODE, STLK.STATUS FROM STATUS_LKUP STLK WHERE STLK.STAT_ID IN (SELECT USRST.STAT_ID FROM USER_STATUS USRST WHERE USRST.UID = 'UID_001');
请帮忙。
信息提供:这不是一项作业任务。实际的表格很复杂,这些只是为了更好的解释而转换的。
提前感谢您的帮助。