在 where 子句中使用 if 语句
如果在 where 语句中,我试图获取日期时间大于 NOW() 的所有行,但如果 type = 'economy',我想将其限制为仅显示 datetime 和 NOW() 之间的 datediff 是否更大超过 14 天。
类似:
Select type,date(datetime) as date
from tbl1
where datetime > NOW()
IF(type = 'economy') && datediff(datetime,NOW()) > 14
order by datetime desc
我也尝试过使用案例,但无法弄清楚......
With if in a where statement I'm trying to get all rows where datetime is larger then NOW(), but if type = 'economy', i would like to constraint it to only show if datediff between datetime and NOW() is larger than 14 days.
Something like:
Select type,date(datetime) as date
from tbl1
where datetime > NOW()
IF(type = 'economy') && datediff(datetime,NOW()) > 14
order by datetime desc
I've tried with case when also, but can't figure it out...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将标准分为 2 个不同的比较:(
未检查语法错误,但想法应该是正确的......)
You can just separate the criteria into 2 different comparisons:
(Not checked for syntax errors, but the idea should be right...)
'
'