以下のように3つのテーブルがあります。
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 DB に作成されます。渡されたユーザーの 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');
助けてください。
参考:これは宿題ではありません。実際の表は複雑で、説明をわかりやすくするために変換しただけです。
前もって感謝します。