【发布时间】:2018-12-24 07:21:43
【问题描述】:
我有查询检查是否 close_at >= '00:00' + 间隔 1 天,否则不添加间隔。我的查询是:
select * from table where now() between open_at and if(close_at >= '00:00' close_at + INTERVAL 1 day, close_at - INTERVAL 1 day)
【问题讨论】:
-
您的问题到底是什么?请提供minimal reproducible example,包括预期和实际结果。
-
解释这部分 '23:00' 在 open_at 和 if(close_at >= '00:00' close_at + INTERVAL 1 day, close_at - INTERVAL 1 day)'之间的位置'
-
您不能在 WHERE 中执行计算。您需要选择该值并使用 HAVING
-
分享您的样本数据预期输出
-
例如,我有数据:没有 | open_at | close_at 1 | 08:00 | 23:00 2 | 08:00 | 00:00 3 | 09:00 | 02:00 如果 close_at >= 00:00 我必须添加间隔 1 天,我现在如何编写选择时间查询,否则不要添加间隔 1 天 @ZaynulAbadinTuhin