按小时
select CONVERT(varchar(13),createdtime,120)+':00:00' as adddate1,count(*) as allhour from [User] group by CONVERT(varchar(13),CreatedTime ,120)
--按日 selectsum([统计字段]),day([时间字段]) from 表明 whereyear([时间字段]) ='2009'groupbyday([时间字段])
--按周
selectsum([统计字段]),datename(week,[时间字段]) from consume_record whereyear([时间字段]) ='2009'groupbydatename(week,[时间字段])
--按月
selectsum([统计字段]),month([时间字段]) from consume_record whereyear([时间字段]) ='2009'groupbymonth([时间字段])
--按季
selectsum([统计字段]),datename(quarter,[时间字段]) from consume_record whereyear([时间字段]) ='2009'groupbydatename(quarter,[时间字段])