我正试图在几行上执行“in”:
case when (select distinct A from b ) in ('test,'y') then 2
我收到错误:“子查询返回多行”。 有没有办法使它有效?
编辑:
这个解决方案对我有用:
case when exists (select distinct a from b
where a in ('test','y')) then 2
谢谢大家。
答案 0 :(得分:0)
select count(*) from b
where a in ('x','y')
答案 1 :(得分:0)
保持概念相似:
CASE WHEN EXISTS (SELECT 1 FROM b WHERE a IN ('test', 'y')) THEN 2
如果IN
b
列中需要a
个值,则
CASE WHEN (SELECT COUNT(DISTINCT a) FROM b WHERE a IN ('test','y'))=2 THEN 2
或者,如果您只是想在IN
条件中返回不同值的数量,那么您就不需要CASE
:
SELECT COUNT(DISTINCT a) FROM b WHERE a IN ('test','y')