3

在我SqlServer 2008的表中,我有一个名为 Table1 的表,其中有一列名为IncDateDateTime。

我需要运行一个查询,返回该日期的记录总数。例如,我的表有这些记录:

IncDate
09/09/2012 16:21:51.547
09/09/2012 16:22:11.032
10/09/2012 13:51:33.327

我的查询需要输出:

Date................Total
09/09/2012...........2 
10/09/2012...........1
4

3 回答 3

4

您需要CAST()将日期设置为仅日期。

SELECT Cast(incdate as date) DateOnly, Count(*) AS Total
FROM yourtable
GROUP BY Cast(incdate as date)

SQL Fiddle with Demo

如果您没有CAST()仅日期到日期,则计数将关闭。

于 2012-09-10T15:57:23.853 回答
0

这是一种方法:

select cast(incdate as date) as date, count(*)
from table1
group by cast(incdate as date)
order by 1
于 2012-09-10T15:56:10.100 回答
0

尝试

SELECT cast(incdate as [date]) as [idate], count(incdate) totalCount
FROM table1
GROUP BY cast(incdate as [date])
ORDER BY totalCount
于 2012-09-10T15:59:26.100 回答