OK I might be asking a stupid question, but I'm banging my head over this..
Say I have a table like so:
FullName | DownloadDate
-------- | -----------------------
Jack | 2012-03-21 00:00:00.000
Joe | 2012-03-21 00:00:00.000
John | 2012-03-22 00:00:00.000
I want to return the number of downloads by date so the resulting table is:
DownloadDate | TotalDownloaded
------------------------| ---------------
2012-03-21 00:00:00.000 | 2
2012-03-22 00:00:00.000 | 1
How can I achieve this?
Also, you can assume that in my date column in the original data, I will always have a time of '00:00:00.000'.
The SQL GROUP BY Statement The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country". The GROUP BY statement is often used with aggregate functions ( COUNT() , MAX() , MIN() , SUM() , AVG() ) to group the result-set by one or more columns.
The use of COUNT() function in conjunction with GROUP BY is useful for characterizing our data under various groupings. A combination of same values (on a column) will be treated as an individual group.
Using COUNT, without GROUP BY clause will return a total count of a number of rows present in the table. Adding GROUP BY, we can COUNT total occurrences for each unique value present in the column.
COUNT(*) returns the number of rows in a specified table, and it preserves duplicate rows. It counts each row separately. This includes rows that contain null values.
try this:
SELECT DownloadDate, Count(DownloadDate) as TotalDownloaded
FROM yourtable
GROUP BY DownloadDate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With