如何查询同一个时间段内但不同日期的数据,例如:2017年3月1日到2017年6月1日中每天早上8点到9点的数据。
select * from 表 where 日期字段>='开始日期' and 日期字段<='截止日期'
and convert(char(8),日期字段,108)>='开始时间' and convert(char(8),日期字段,108)<='截止时间'
例如:
select * from tb1 where dDate>='2010-11-05' and dDate<='2010-11-15'
and convert(char(8),dDate,108)>='8:00:00' and convert(char(8),dDate,108)<='9:00:00'
sqlserver 用convert 108得到时间部分,更多参考:http://www.cnblogs.com/weiqt/articles/2040800.html