如何在caes语句中使用子查询

时间:2017-06-05 01:27:16

标签: sql select subquery case

我想在case语句中使用select ~~~~ subquery 但我不知道该怎么做

我的想法是

案例何时 (选择......来自...其中..)IS为空 然后 ... 否则...... 结束......

但它无效

1 个答案:

答案 0 :(得分:0)

您可以执行临时表并查询

with
test as (select names from table where names=smith ) ---You can add in left 
--joins here or whatever - again not sure what you are trying to accomplish
select Case when name=smith then "Yes" else Null end as Case_test
from test

使用子查询可能是一种更简单的方法,但我不确定。我们需要更多关于你想要完成什么的细节,但这可能会成功。