34,838
社区成员




declare @A table (日期时间 datetime,ll int,ll1 int)
insert @A select '2008-2-15 9:00:00',300,200
insert @A select '2008-2-15 10:00:00',800,600
insert @A select '2008-2-15 11:00:00',2000,1000
select
日期时间,
[ll]=ll-isnull((select ll from @A where 日期时间=(select max(日期时间) from @A where 日期时间<t.日期时间)),0),
[ll1]=ll1-isnull((select ll1 from @A where 日期时间=(select max(日期时间) from @A where 日期时间<t.日期时间)),0)
from
@A t
(所影响的行数为 1 行)
(所影响的行数为 1 行)
(所影响的行数为 1 行)
日期时间 ll ll1
------------------------------------------------------ ----------- -----------
2008-02-15 09:00:00.000 300 200
2008-02-15 10:00:00.000 500 400
2008-02-15 11:00:00.000 1200 400
(所影响的行数为 3 行)
select
日期时间,
[ll]=ll-isnull((select ll from A where 日期时间=(select max(日期时间) from A where 日期时间<t.日期时间)),0),
[ll1]=ll1-isnull((select ll1 from A where 日期时间=(select max(日期时间) from A where 日期时间<t.日期时间)),0)
from
A t