您的位置:首页 > 数据库

sqlserver中如何实现时间按月,日,小时分组查询

2011-10-19 11:32 507 查看
--按照月份统计

select count(id) cnt,datepart(mm,time) [Month]

from where [time] between '2007/09/08 09:10:43' and '2007/10/09 04:32:37'

group by datepart(mm,time)

--按照日统计

select count(id) cnt,datepart(dd,time) [Day]

from
where time between '2007/09/08 09:10:43' and '2007/10/09 04:32:37'

group by datepart(dd,time)

--按照小时统计

select count(id) cnt,datepart(hh,time) [Hour]

from
where [time] between '2007/09/08 09:10:43' and '2007/10/09 04:32:37'

group by datepart(hh,time)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: