我想用条件'和'执行SQL选择查询。条款但有困难。
我想做这样的事情:
select * from customer
where active = true
and
case
when state = 'AK'
then zipcode like '%701'
when state = 'NV'
then zipcode like '%523'
else
then phone not null;
如何构建查询来执行此操作?
提前感谢您提供的任何指导。
答案 0 :(得分:1)
你的意思是?
select * from customer
where active = true
and ((state = 'AK' and zipcode like '%701')
or (state = 'NV' and zipcode like '%523')
or (phone not null))
答案 1 :(得分:1)
我认为您可以使用or
代替case
。
select * from customer
where active = true
and ( (state = 'AK' and zipcode like '%701') or (state = 'NV' and zipcode like '%523') )
and phone is not null;