要求查询到
00:00 - 01:00 5条
01:00 - 02:00 10条............. 。
22:00 - 23:00 8条
23.:: - 00:00 3条要查询到一个月的按时间段的这样的SQL怎么写
00:00 - 01:00 5条
01:00 - 02:00 10条............. 。
22:00 - 23:00 8条
23.:: - 00:00 3条要查询到一个月的按时间段的这样的SQL怎么写
解决方案 »
- DataTable批量更新
- asp.net如何改变TreeView控件的图标
- 模板引擎中使用服务器控件,有办法么?
- GridView除了绑定字段列外,一个模板列中放置了CheckBox,其余的四个模板列分别放置了TextBox1 - 4,绑定后几乎死机
- [玻璃鱼V]关于动态添加控件的问题,大家快来看哪
- ScriptManager同时存在于两个文件中???
- dropdownlist的取值问题
- 高分请教网业技巧???
- !!!!!!!!!!!!!!!!!!!!!!!!!关于dataset的问题%%%%%%%%%%(线等)
- 如何限制用户修改txtbox的值呢?使用户无法输入到txtbox里面的值?
- 包含外部文件问题.
- 怎么把一个页面中的几个函数构造成一个类 方便调用?
select * from table where (时间 between 开始时间 and 结束时间) and (datediff(m,时间,月份) = 0)
//例:
select * from table where (UploadDate between '2008-1-1 00:00' and '2008-1-1 01:00') and (datediff(m,UploadDate,'2008-1-1 00:00'))
//当然开始时间,结束时间的月份和查询的月份要相同
create table testTable
(
pid int identity (1,1),
date_created datetime,
rowid nvarchar(64)
)insert testTable values (dateadd(hh, 1, getdate()), cast(newid() as varchar(64)))
insert testTable values (dateadd(hh, 1, getdate()), cast(newid() as varchar(64)))
insert testTable values (dateadd(hh, 3, getdate()), cast(newid() as varchar(64)))
insert testTable values (dateadd(hh, 3, getdate()), cast(newid() as varchar(64)))
insert testTable values (dateadd(hh, 1, getdate()), cast(newid() as varchar(64)))
insert testTable values (dateadd(hh, 5, getdate()), cast(newid() as varchar(64)))
insert testTable values (dateadd(hh, 5, getdate()), cast(newid() as varchar(64)))
insert testTable values (dateadd(hh, 1, getdate()), cast(newid() as varchar(64)))
insert testTable values (dateadd(hh, 4, getdate()), cast(newid() as varchar(64)))
select * from testTableselect
datepart(MM, date_created) AS [Month],
datepart(dd, date_created) AS [Day],
datepart(hh, date_created) AS [Hour],
count(pid) as ItemCount
from testtable
group by datepart(MM, date_created), datepart(dd, date_created), datepart(hh, date_created)drop table testTable
在Query中用月份做过滤即可
----------- ----------- ----------- -----------
5 11 0 4
5 11 2 2
5 11 3 1
5 11 4 2(4 row(s) affected)这是查询结果
sql语句集锦