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

SQL!急急急
取出昨天以前的数据,且日期的时分秒在23点之前的。急急急!。忘高手指教

------解决方案--------------------
SQL code

select *
from date < getdate()-1
    and datepart(hh,date) < 23

------解决方案--------------------
--取出昨天以前的数据,且日期的时分秒在23点之前的。急急急!。忘高手指教

create table #t(
id int identity(1,1),
dtime datetime
)
insert #t
select '2012-02-11 13:23:06' union all
select '2012-02-10 11:23:06' union all
select '2012-01-19 23:23:06' union all
select '2012-01-18 13:23:06' union all
select '2012-02-09 20:23:06' union all
select '2012-02-11 10:23:06'

select *from #t where dtime<GETDATE()-1 and DATEPART(hh,dtime) < 23

/*
id dtime
2 2012-02-10 11:23:06.000
4 2012-01-18 13:23:06.000
5 2012-02-09 20:23:06.000
*/