我想编写一个sql查询:
if
此查询(select X from table1 where x = 'value1')
有结果返回1 else if (select x from table2 where x = 'value2')
有任何结果返回2否则返回0.
谢谢
一种方法是select
和case
:
select (case when exists (select X from table1 where x = 'value1') then 1 when exists (select x from table2 where x = 'value2') then 2 else 0 end) as flag