我有一个名为 content
的表带字段id
, namew
, publish_date
, unpublish_date
publish_date
和unpublish_date
两者都可以 null
现在我想选择数据如果 publish_date is not null
然后publish_date <= CURDATE()
我尝试使用此查询
select *
from content
where if(publish_date is not null, publish_date <= CURDATE(),'')
但我不知道在其他情况下该放什么。因为我只需要 if 条件而不是 else 条件
最佳答案
您应该编写相互排除的条件:
select *
from content
where publish_date is null
or publish_date <= CURDATE()
关于php - mysql where 子句中的 if 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29792067/