我需要在给定日期范围内的每天上午9点至下午6点之间对表中的记录数进行计数。
样本输出应类似于:
Date Count of users
01-11-2018 100
02-11-2018 88
03-11-2018 107
04-11-2018 113
答案 0 :(得分:-1)
SELECT DATE(date), count(*)
FROM table
WHERE TIME(date) BETWEEN TIME('9:00:00') AND TIME('18:00:00')
GROUP BY DATE(date)
答案 1 :(得分:-1)
SELECT `date`,
Count(*)
FROM table_name tn
WHERE tn.date >= Timestampadd(hour, 9, Curdate())
AND tn.date <= Timestampadd(hour, 18, Curdate())
GROUP BY `date`