日期:2014-05-18  浏览次数:20523 次

使用日期进行分组统计问题???
在数据表中存储的是带有时间的日期值如:

2007-9-8   14:00:00  
2007-9-8   15:00:00
...

需要做到以日期进行分组统计,也就是统计2007-9-8的所有记录数量。

Select   Count(ID),[Date]   From   TestTable   Group   By   [Date],ID   --如果这样写就会将上面的记录分成二组,我只想按日期进行分组,该如何编写SQL。

------解决方案--------------------
Select Count(ID),[Date]= convert(varchar(6),[Date],112) From TestTable Group By convert(varchar(6),[Date],112)
------解决方案--------------------
Select Count(ID),[Date]= convert(varchar(10),[Date],120) From TableName Group By convert(varchar(10),[Date],120)
------解决方案--------------------
select convert(varchar(10),[date],120) 日期,count(*) from tb group by convert(varchar(10),[date],120)
------解决方案--------------------
哦,看错,我以为是按月统计,按天这样:

Select Count(ID),[Date]= convert(varchar(8),[Date],112) From TestTable Group By convert(varchar(8),[Date],112)