[英]How to use 'IN' clause in case statement DB2 sql
在 IBM DB2 sql 中运行类似查询时出现错误:
select case
when col1 in (select colA from tabl01) then 'xyz'
else 'abc'
end as colD
from tabl02
错误就像
“查找错误 - DB2 数据库错误:错误 [42625] [IBM][DB2] SQL0582N VALUES 子句、IN 谓词、GROUP BY 子句或 ORDER BY 子句中的 CASE 表达式不能包含量化谓词、使用全查询的 IN 谓词, 或 EXISTS 谓词。”
我认为这个问题是因为在我的案例陈述中使用了“in”。 如何消除此错误?
像这样更改您的查询。 应该适用于大多数 DB2 平台。
select case
when exists (select 1 from tabl01 lkup
where lkup.cola = src.col1
fetch first 1 rows only)
then 'xyz'
else 'abc'
end as cold
from tabl02 src
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.