"SELECT count(id) AS total FROM participant where dateofbooking='$datepick'";
我正在使用此代码。但是它只显示一个日期(从php中选择日期)计数。但是我想选择一个日期,它应该可以显示每天最多5天的明智预订。
输出应如下所示:-
2018-05-20------>48
2018-05-21------>58
2018-05-22------>67
2018-05-23------>78
2018-05-24------>43
答案 0 :(得分:1)
您可以使用DATE_ADD()
:
SELECT dateofbooking, count(id) AS total
FROM participant
WHERE dateofbooking >= $datepick AND
dateofbooking <= DATE_ADD($datepick, INTERVAL 5 DAY)
GROUP BY dateofbooking;
答案 1 :(得分:0)
您可以将其按使用的日期列进行分组,如果需要多天,则可以添加dateofbooking >= some_start_date
和dateofbooking <= some_end_date
"SELECT count(id) AS total FROM participant where dateofbooking='$datepick' group by dateofbooking";
倍数可能看起来像
"SELECT count(id) AS total FROM participant where dateofbooking>='$datepickstart' AND dateofbooking<='$datepickend' group by dateofbooking";
答案 2 :(得分:-2)
您可以使用between
。请参见下面的示例:
SELECT count(id) AS total FROM participant where dateofbooking between cast( GETDATE() as Date) and Cast(DATEADD(DAY,-5, GETDATE()) as DATE)
Group by CAST( dateofbooking AS DATE)
另外,使用group by Date
。
注意:这不是MySQL的解决方案。它适用于SQL Server。