[英]How to use 'IN' clause in case statement DB2 sql
I am getting an error while running similar query like below in IBM DB2 sql:在 IBM DB2 sql 中运行类似查询时出现错误:
select case
when col1 in (select colA from tabl01) then 'xyz'
else 'abc'
end as colD
from tabl02
The error is like错误就像
"Lookup Error - DB2 Database Error: ERROR [42625] [IBM][DB2] SQL0582N A CASE expression in a VALUES clause, IN predicate, GROUP BY clause, or ORDER BY clause cannot include a quantified predicate, an IN predicate using a fullselect, or an EXISTS predicate."
“查找错误 - DB2 数据库错误:错误 [42625] [IBM][DB2] SQL0582N VALUES 子句、IN 谓词、GROUP BY 子句或 ORDER BY 子句中的 CASE 表达式不能包含量化谓词、使用全查询的 IN 谓词, 或 EXISTS 谓词。”
I think the issue is because of using 'in' in my case statement.我认为这个问题是因为在我的案例陈述中使用了“in”。 How can I remove this error?
如何消除此错误?
Change your query like this.像这样更改您的查询。 Should work on most DB2 platforms.
应该适用于大多数 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.