繁体   English   中英

仅当匹配列不为空时

[英]Match Column only if it is not empty

我只想匹配不为空的列

select *
from users
where message = 'test' AND phone like '%813%'

仅当phone列不为null时,才应调用条件

否则下面的查询应该被调用

select * from users where message = 'test'

意味着仅当phone不为null时才应调用AND phone like '%813%'

使用CASE

select *
from users
where message = 'test' AND 
    case when phone is not null 
    then phone like '%813%'
    else 1 end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM