lol*_*lol -8 c# sql sql-server
我想编写一个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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2849 次 |
| 最近记录: |