SQL:如何使用条件where子句构造select查询?

SQL:如何使用条件where子句构造select查询?,sql,Sql,我想使用条件'and'子句执行SQL select查询,但遇到困难 我想这样做: 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 n

我想使用条件'and'子句执行SQL select查询,但遇到困难

我想这样做:

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;
如何构建查询以实现这一点

提前感谢您提供的指导。

您的意思是

select * from customer
where active = true
and ((state = 'AK' and zipcode like '%701')
    or (state = 'NV' and zipcode like '%523')
    or (phone not null))

我想你可以用
代替
案例

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;

我认为
和/或
一样有效。所以他需要一个排他性的
我想也许你应该试着阅读文档。这是给你的