我有一个ShoppingDates的日期时间列。
假设我有1000行
我想计算每次在一小时时间内出现的次数
so 5:00 p.m - 5:59:59 pm
so 6:00 p.m - 6:59:59 pm
so 7:00 p.m - 7:59:59 pm
so 8:00 p.m - 8:59:59 pm
所以在上面的结果中我会得到
1|5pm-6pm
1|6pm-7pm
1|7pm-8pm
2|8pm-9pm
感谢任何帮助。
谢谢!
答案 0 :(得分:50)
我怀疑你只想要这样的东西:
SELECT HOUR(ShoppingDate), COUNT(*) FROM YourTable
GROUP BY HOUR(ShoppingDate)
答案 1 :(得分:3)
试试这个
SELECT
CONCAT( HOUR(ShoppingDate), ' to ', CONCAT( HOUR(ShoppingDate), ':59:59' ) ) as time_frame,
COUNT(*)
FROM
temp
GROUP BY
DATE(ShoppingDate),
HOUR(ShoppingDate)
注意:我认为ShoppingDate是一个日期时间字段