34,590
社区成员
发帖
与我相关
我的任务
分享
set nocount on
declare @t table(nDate datetime, Temperature float, FileDate datetime)
insert @t select '2008-01-01 12:53', 12.5 , '2008-01-01'
insert @t select '2008-01-01 20:00', 7.5 , '2008-01-01'
insert @t select '2008-01-01 21:12', 15.5 , '2008-01-01'
insert @t select '2008-01-01 22:53', 9.5 , '2008-01-01'
insert @t select '2008-01-02 22:53', 9.5 , '2008-01-02'
select filedate from (
select filedate=(case when datepart(hh,ndate)>20 then dateadd(dd,1,filedate)else filedate end) from @t ) t group by filedate
/*
filedate
------------------------------------------------------
2008-01-01 00:00:00.000
2008-01-02 00:00:00.000
2008-01-03 00:00:00.000
*/
--> 测试数据: @sMeteTable
declare @sMeteTable table (nDate datetime,Temperature numeric(3,1),FileDate datetime)
insert into @sMeteTable
select '2008-01-01 12:53',12.5,'2008-01-01' union all
select '2008-01-01 21:00',7.5,'2008-01-01' union all
select '2008-01-01 21:12',15.5,'2008-01-01' union all
select '2008-01-02 22:53',9.5,'2008-01-01' union all
select '2008-01-03 22:53',9.5,'2008-01-02'
select convert(varchar(10),ndate,120) from @sMeteTable where datepart(hh,ndate)>20 group by convert(varchar(10),ndate,120)