SQL Server 2008中的分组和计数

Ash*_*hes 8 t-sql sql-server sql-server-2008 sql-server-2008-r2

好吧我可能会问一个愚蠢的问题,但我正在敲打这个问题.

说我有这样一张桌子:

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
Run Code Online (Sandbox Code Playgroud)

我想按日期返回下载次数,因此得到的表格是:

DownloadDate            | TotalDownloaded
------------------------| ---------------
2012-03-21 00:00:00.000 | 2
2012-03-22 00:00:00.000 | 1
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

此外,您可以假设在原始数据的日期列中,我将始终拥有'00:00:00.000'的时间.

Tar*_*ryn 19

试试这个:

SELECT DownloadDate, Count(DownloadDate) as TotalDownloaded
FROM yourtable
GROUP BY DownloadDate
Run Code Online (Sandbox Code Playgroud)