求一段查询时间段
比如我数据库时有数据
开始时间 结束时间
2012-08-15 09:00:00 2012-08-15 10:00:00
2012-08-16 09:00:00 2012-08-16 10:00:00
2012-08-15 10:00:00 2012-08-15 11:00:00
2012-08-15 11:00:00 2012-08-15 12:00:00
我想要查询每天9点到10点的数据`
就像第一条与每二条符合`
要怎么写
[解决办法]
declare @T table([开始时间] datetime,[结束时间] datetime)insert @Tselect '2012-08-15 09:00:00','2012-08-15 10:00:00' union allselect '2012-08-16 09:00:00','2012-08-16 10:00:00' union allselect '2012-08-15 10:00:00','2012-08-15 11:00:00' union allselect '2012-08-15 11:00:00','2012-08-15 12:00:00'select * from @Twhere datepart(hh,开始时间)=9 and (datepart(hh,结束时间) in (9,10))/*开始时间 结束时间----------------------- -----------------------2012-08-15 09:00:00.000 2012-08-15 10:00:00.0002012-08-16 09:00:00.000 2012-08-16 10:00:00.000*/