日期:2014-05-19  浏览次数:20362 次

救急啊 表操作问题
create   TABLE   t(a,int)
insert   t   select   10
select   20
select   8
select   6
......
让下一条记录减去上一条记录
把结果存在 另外一列里
怎么做啊 
谢谢 各位了

------解决方案--------------------
create table T(a int)
insert T select 10
union all select 20
union all select 8
union all select 6

select ID=identity(int, 1, 1),* into #T from T

select a, col2=isnull((select a from #T where ID=tmp.ID+1), 0)-a
from #T as tmp

--result
a col2
----------- -----------
10 10
20 -12
8 -2
6 -6

(4 row(s) affected)