gpt4 book ai didi

sql - 使用基于 case 语句的 SQL IN 语句

转载 作者:行者123 更新时间:2023-12-04 18:11:24 24 4
gpt4 key购买 nike

是否可以使用in基于 case 语句的命令

我尝试过这样的事情

@Id int

Select *
From Table
Where StatusId in( case when Id =1 then 1 else 1,3 end)


    Select * 
From Table
Where StatusId in case when Id =1 then (1) else (1,3) end

有任何想法吗!!

最佳答案

不,您需要以不同的方式解决此问题:

Where (Id = 1 and StatusId in (1)) or (Id <> 1 and StatusId in (1, 3))

这种模式的变化是可能的。

关于sql - 使用基于 case 语句的 SQL IN 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12584716/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com