我有一个查询
sql_query := ' Select A,B,C from table where A = 'DG54FDG45SD' and B = 'FS487' ;
,我想为它添加一个if子句:
sql_query := ' Select A,B,C,D from table where A = 'DG54FDG45SD' and B = 'FS487' and (if C = 'AR' then AND D in (select uid from table2 where id = 'DGF'));
谢谢!
答案 0 :(得分:0)
您不必在if
子句中使用where
来执行此操作-仅仅是因为没有必要。您可以使用基本的布尔运算得出相同的逻辑:
where A = 'DG54FDG45SD' and
B = 'FS487' and
(D in (select uid from table2 where id = 'DGF') or
C <> 'AR'
)
如果您需要考虑NULL
:
where A = 'DG54FDG45SD' and
B = 'FS487' and
(D in (select uid from table2 where id = 'DGF') or
C <> 'AR' or C is null
)