如何根据具体情况进行过滤?
select * from address
where streetnum > 1000 only when state = MI otherwise select everything else
或
select * from address
where case when state = MI then streetnum > 1000
答案 0 :(得分:2)
从address
获取所有行,但当state
为'MI'
时,streetnum
必须大于1000
。
select * from address
where streetnum > 1000 or state <> 'MI'
如果您想使用case
,可能需要检查多个值。
select *
from address
where case state
when 'MI' then 1000
when 'MA' then 1000
else 0
end < streetnum
如果所有州都有相同的值(1000),那就与此相同。
select *
from address
where streetnum > 1000 or state not in ('MI', 'MA')
答案 1 :(得分:2)
如果我正确地解释了你的问题,那么......
select * from address
where state <> 'MI' or (state = 'MI' and streetnum > 1000)