Reputation: 712
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?
Upvotes: 16
Views: 26410
Reputation: 6134
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
Upvotes: 23
Reputation: 2584
use query like this
SELECT COUNT(UserID) AS TOT FROM users GROUP BY DATE(DateJoined)
Upvotes: 1
Reputation: 4487
Try Like This
SELECT COUNT(UserID) AS TOT FROM users GROUP BY CAST(DateJoined AS DATE)
OR
SELECT COUNT(UserID) AS TOT, FROM a_table GROUP BY DATE(DateJoined );
Upvotes: 1