[英]Match Column only if it is not empty
I want to match column only if it is not empty 我只想匹配不为空的列
select *
from users
where message = 'test' AND phone like '%813%'
Where condition should be called only if phone column is not null 仅当phone列不为null时,才应调用条件
else below query should be called 否则下面的查询应该被调用
select * from users where message = 'test'
means AND phone like '%813%'
should be called only if phone is not null 意味着仅当phone不为null时才应调用
AND phone like '%813%'
Use CASE
使用
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.