我每天都要运行一堆任务,应该在同一天完成。所以,我想检查这些任务是否在同一天完成。
$sql = "SELECT date, MIN(date), MAX(date) FROM task_scheduler
WHERE (date >= $date AND date < $date_plus_1day)";
我们说我需要查看以下日期。
$min_date = '2014-12-30';
$max_date = '2015-01-03';
如何获得PHP中给出的日期的每日报告,如下例所示:
date MIN(date) MAX(date)
2014-12-30 2014-12-30 2014-12-31 (didn't complete on same day)
2014-12-31 2014-12-31 2014-12-31 (completed on same day)
2015-01-01 2015-01-01 2015-01-01 (completed on same day)
2015-01-02 2015-01-02 2015-01-03 (didn't complete on same day)
2015-01-03 2015-01-03 2015-01-05 (didn't complete on same day)
答案 0 :(得分:1)
使用HAVING
子句。它适用于应用聚合函数后。
...
WHERE ...
HAVING MAX(date) = MIN(date) + INTERVAL 1 DAY;