日期:2014-05-18  浏览次数:20519 次

关于datatime类型查询
小弟想请教一下。库里一字属是datetime类型,我要查询3小时内6小时内或者是2007-12-01至2007-12-11这十一天内的记录

这样该如何进行判断呢。。麻烦大伙了。

------解决方案--------------------
SQL code
select *
 from tb
   where (datediff(hour,dt,getdate()) between 3 and 6) or
         (dt between '2007-12-01' and '2007-12-11')

------解决方案--------------------
SQL code
select * from tb where 字段 between '2007-12-01' and '2007-12-11'

------解决方案--------------------
SQL code
三小时,六小时,估计得用分钟来算才是你的本意.

select * from tb where datediff(mi,时间字段,getdate()) <= 180
select * from tb where datediff(mi,时间字段,getdate()) <= 360


2007-12-01至2007-12-11

select * from tb where convert(varchar(10),时间字段,120) between '2007-12-01' and '2007-12-11'

------解决方案--------------------
SQL code
2007-12-01至2007-12-11

select * from tb where 时间字段 between '2007-12-01' and '2007-12-11'