无法在 SQL 中的 CASE WHEN 条件 THEN 数组中使用 WHERE 值

Unable to use WHERE value in CASE WHEN condition THEN array in SQL

我正在尝试执行这条语句


SELECT *
FROM trade t
where 
month(t.created_date) 
in 
(case when t.id is null then month(t.created_date) else ( 1,2,3 ) end) 
;

收到此错误

Error Code: 1241. Operand should contain 1 column(s)

知道哪里出了问题吗?

嗯。 . .我想这就是你想要的逻辑:

select t.*
from trade t
where t.id null or month(t.created_date) in (1, 2, 3);

用于 in 的列表不能作为 case 表达式的值返回。