David542
David542

Reputation: 110123

SQL to get count by date

I would like to get the number of rows in a table for each date. Right now I am doing:

SELECT SUM(COUNT(*)) FROM videos_videoview GROUP BY date

What would be the correct syntax for the above?

In addition, the date is stored not as a date, but as datetime (2012-01-25 10:26:20). How would I GROUP BY date here, ignoring the time?

Upvotes: 1

Views: 399

Answers (2)

user554546
user554546

Reputation:

As per the documentation, the DATE() function truncates a timestamp down to a date.

select DATE(date),count(1)
from videos_videoview
group by DATE(date);

Honestly, this is very, very basic SQL. Please read through the documentation of whatever RDBMS you're using or get a basic book on SQL.

Documentation: read it. Love it. Use it.

Upvotes: 7

Jer In Chicago
Jer In Chicago

Reputation: 828

select date, count(*) from videos_videoview group by date;

Which DB are you using?

Upvotes: 1

Related Questions