要求 两个时间点:一个开始时间(2007/09/08 09:10:43),一个结束时间(2007/10/09 04:32:37)
数据库中表的字段有 id(编号) name(名字) time(注册时间) 表名为table
需要查询比如在两个时间段内 比如如上面时间点
求:1.9月,10月分别有多少个id?
2.两个时间段的单个日中分别有多少个id?
3两个时间段的单个小时中分别有多少个id?
我的思路是分别按 月,日,小时分组,然后统计? select count(id) from table where time>='2007/09/08 09:10:43' and time<=
'2007/10/09 04:32:37'
但我做出来的都只能按秒分组,请各位高人指点 怎么才能实现 按月或者按日,按小时分组?先谢谢啦!!
数据库中表的字段有 id(编号) name(名字) time(注册时间) 表名为table
需要查询比如在两个时间段内 比如如上面时间点
求:1.9月,10月分别有多少个id?
2.两个时间段的单个日中分别有多少个id?
3两个时间段的单个小时中分别有多少个id?
我的思路是分别按 月,日,小时分组,然后统计? select count(id) from table where time>='2007/09/08 09:10:43' and time<=
'2007/10/09 04:32:37'
但我做出来的都只能按秒分组,请各位高人指点 怎么才能实现 按月或者按日,按小时分组?先谢谢啦!!
select month([Time]),count(id) from [Table] where [time] between 开始 and '结束' group by month([Time])
2.
select convert(varchar(10),[Time],120),count(id) from [Table] where [time] between 开始 and '结束' group by convert(varchar(10),[Time],120)3.select convert(varchar(13),[Time],120),count(id) from [Table] where [time] between 开始 and '结束' group by convert(varchar(13),[Time],120)
select convert(varchar(7),[Time],120),count(id) from [Table] where [time] between 开始 and '结束' group by convert(varchar(7),[Time],120)