Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group by the date part of a timestamp field

I have users table. I would like to generate a report of user who joined for that day. Problem is, my DateJoined field is a timestamp field,

As the query is following as:

SELECT COUNT(UserID) AS TOT FROM users GROUP BY DateJoined

does not work, how do I get it to GROUP BY just the date part and not the time of DateJoined field?

like image 706
Zaid Kajee Avatar asked Mar 24 '14 10:03

Zaid Kajee


1 Answers

your code:

SELECT 
      COUNT(UserID) AS TOT 
      FROM users 
      GROUP BY DateJoined

you should change like as:

SELECT 
       DATE(DateJoined), 
       COUNT(UserID) AS TOT 
       FROM users 
       GROUP BY DATE(DateJoined)

the sqlfiddle

like image 108
jmail Avatar answered Nov 04 '22 14:11

jmail