SQL Server选择具有不同字段值的不同where条件

Kha*_*her 0 sql sql-server select conditional where-clause

我想从我的表中选择offer有一个字段的数据type,我需要对每种类型应用不同的条件.

代码可能如下所示:

select * from offer where 
if type = 1 then apply condition_1,
else if type = 2 then apply condition_2 and condition_3,
else if type = 3 then apply condition_4,
Run Code Online (Sandbox Code Playgroud)

那我怎么能实现呢?

Avi*_*tus 5

select * from offer
where (type =1 and condition_1 )
or ( type = 2 and condition_2 and condition_3 ) 
or (type = 3 and condition_3 ) 
Run Code Online (Sandbox Code Playgroud)