user1271930 user1271930 - 1 month ago 7
MySQL Question

MySQL query to count total number of orders made by hour returns always 1 for each hour

I have following query which is supposed to count the total number of orders made by hour.

The problem is that total number is always 1 per hour. I have similar query for weekdays which works just fine. What is wrong or missing in the following query?

SELECT COUNT(`Orderno`) as 'totals', EXTRACT(HOUR FROM `order_datetime`) as 'hour'
FROM `orders`
GROUP BY `order_datetime`


Results are

totals hour
1 0
1 1
1 2
...

Answer
SELECT COUNT(`Orderno`) as 'totals', EXTRACT(HOUR FROM `order_datetime`) as   'hour'
FROM `orders`
GROUP BY `order_datetime`,EXTRACT(HOUR FROM `order_datetime`)

Try it

Comments