我需要從返回標記的select語句中的子查詢中選擇列NewFlag。當 子查詢與主要查詢具有匹配條件並且標誌具有結果'U'時,NewFlag 列應該是'/ U'else''。如果子查詢與主查詢不匹配,那麼NewFlag應該是'/ R'。Oracle選擇列作爲子查詢與case語句
Create table abc (ID int,SLSID int,FLag char)
Create table master(ID int ,SLSID int)
insert into abc values(1001,123,P)
insert into abc values(1002,123,A)
insert into abc values(1003,123,U)
insert into abc values(1004,133,U)
Insert into master (1001,123)
Insert into master (1002,123)
Insert into master (1003,123)
Insert into master (1004,123)
結果應該是
1003 123 '/U' - since abc had matching entry in master and Flag is 'U'
1001 123 '' - since abc had matching entry in master but Flag is not 'U'
1002 123 '' - since abc had matching entry in master but Flag is not 'U'
1004 133 '/R' - no matching entry for abc in master
謝謝@Thomas Tschernich –