我有以下查询,该查询应该按小时计算订单总数。
问题是总数总是每小时1。我有类似的工作日查询,工作得很好。以下查询中有什么错误或缺失?
SELECT COUNT(`Orderno`) as 'totals', EXTRACT(HOUR FROM `order_datetime`) as 'hour'
FROM `orders`
GROUP BY `order_datetime`
结果
totals hour
1 0
1 1
1 2
...
答案 0 :(得分:1)
SELECT COUNT(`Orderno`) as 'totals', EXTRACT(HOUR FROM `order_datetime`) as 'hour'
FROM `orders`
GROUP BY `order_datetime`,EXTRACT(HOUR FROM `order_datetime`)
试试吧
答案 1 :(得分:0)
group by hour(order_datetime)
应该这样做。