【发布时间】:2017-08-02 06:37:54
【问题描述】:
我需要从返回 Flag 的 select 语句中的子查询中选择 Column NewFlag。什么时候 子查询与主查询具有匹配条件,Flag 的结果为“U”,然后是 NewFlag 列应为“/U”,否则为“”。如果子查询与主查询不匹配,则 NewFlag 应为 '/R'。
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
【问题讨论】: