[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 512
  • Last Modified:

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'
0
babak62
Asked:
babak62
  • 2
1 Solution
 
Aaron TomoskyTechnology ConsultantCommented:
Datepart(hour, reg_timestamp) as reghour

Group by reghour
0
 
SharathData EngineerCommented:
try this.
SELECT HOUR(REG_TIMESTAMP), 
         COUNT(t_user.USERID) 
    FROM t_user 
   WHERE `REG_TIMESTAMP` BETWEEN '2011-04-20 00:00:00' AND '2011-04-20 23:59:59' 
GROUP BY HOUR(REG_TIMESTAMP)

Open in new window

0
 
babak62Author Commented:
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
0
 
Aaron TomoskyTechnology ConsultantCommented:
You forgot the comma before datepart
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now