create TABLE t(a,int)
insert t select 10
select 20
select 8
select 6
......
让下一条记录减去上一条记录
把结果存在 另外一列里
怎么做啊
谢谢 各位了
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
..............
insert T select 10
union all select 20
union all select 8
union all select 6select ID=identity(int, 1, 1),* into #T from Tselect 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)
#t是临时表 tep是它的别名
insert T select 10
union all select 20
union all select 8
union all select 6select ID=identity(int, 1, 1),* into #T from Tselect a, col2=a-isnull((select a from #T where ID=tmp.ID-1), 0)
from #T as tmp--result
a col2
----------- -----------
10 10
20 10
8 -12
6 -2(4 row(s) affected)
是把0替换成?
他也没有值啊
把NULL替换成0
那isnull((select a from #T where ID=tmp.ID-1), 0)他的结果就全是0 那有什么意义啊