Group and Count in SQL Server 2008

13,630

Solution 1

try this:

SELECT DownloadDate, Count(DownloadDate) as TotalDownloaded
FROM yourtable
GROUP BY DownloadDate

Solution 2

SELECT DownloadDate, COUNT(DownloadDate) [TotalDownloaded]
FROM TableName
GROUP BY DownloadDate
Share:
13,630
AshesToAshes
Author by

AshesToAshes

Updated on July 29, 2022

Comments

  • AshesToAshes
    AshesToAshes almost 2 years

    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'.

  • Teja
    Teja about 12 years
    I posted this answer from my stackoverflow mobile app before... Thats why couldn't post in aligned manner...
  • Martin Smith
    Martin Smith about 12 years
    GROUP BY 1 is not valid in SQL Server