如下表
DT Value
2008-1-1 1:01 23
2008-1-1 1:32 25
2008-1-1 1:59 27
2008-1-1 2:06 28
2008-1-1 2:46 29
2008-1-1 3:06 37
2008-1-1 3:26 41
2008-1-1 3:56 42
2008-1-1 4:00 42
结果为
DT Value
2008-1-1 1时 5 (28-23)
2008-1-1 2时 9 (37- 28)
2008-1-1 3时 5 (42- 37)
这个问题第1个回答:
DT Value
这个问题第2个回答:
- SQL code
select convert(char(10),c.dt,120),a.value - b.value as value from ( select * from ta a where not exists(select 1 from ta where convert(char(13),a.dt,120) = convert(char(13),dt,120) and dt > a.dt) ) c left join ( select * from ta a where not exists(select 1 from ta where convert(char(13),a.dt,120) = convert(char(13),dt,120) and dt < a.dt) b on convert(char(13),c.dt,120)= convert(char(13),b.dt,120)