babak62
asked on
Count Mysql result by hour
Hi this is my query which counts my new users registered per day. I am trying to find out to make this to show results per hour also whitin 24 hours show how many users signed up in which hour like 11:00 10 uers and 12:00 15 etc...
Is there anyway to change this to accomplish thisi task. Then again thanks for the help
SELECT COUNT(t_user.USERID)
FROM
t_user
WHERE
`REG_TIMESTAMP` BETWEEN '2011-04-20 00:00:00' AND '2011-04-20 23:59:59'
Is there anyway to change this to accomplish thisi task. Then again thanks for the help
SELECT COUNT(t_user.USERID)
FROM
t_user
WHERE
`REG_TIMESTAMP` BETWEEN '2011-04-20 00:00:00' AND '2011-04-20 23:59:59'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the answer I did like this
SELECT COUNT(t_user.USERID)
Datepart(hour, reg_timestamp) as reghour
FROM
t_user
WHERE
`REG_TIMESTAMP` BETWEEN '2011-04-20 00:00:00' AND '2011-04-20 23:59:59'
Group by reghour
and this was the error
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(hour, reg_timestamp) as reghour
FROM
t_user
WHERE
`REG_TIMESTAMP` BETWEEN ' at line 2
SELECT COUNT(t_user.USERID)
Datepart(hour, reg_timestamp) as reghour
FROM
t_user
WHERE
`REG_TIMESTAMP` BETWEEN '2011-04-20 00:00:00' AND '2011-04-20 23:59:59'
Group by reghour
and this was the error
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(hour, reg_timestamp) as reghour
FROM
t_user
WHERE
`REG_TIMESTAMP` BETWEEN ' at line 2
You forgot the comma before datepart
Group by reghour