5
表我有這個表更新與前柱,用任何環路
test123
rn pds pv bl ag pg
1 6817 90 15 1 1
2 6817 12 1 1
3 6817 10 1 2
4 6817 10 1 3
5 6817 11 1 2
1 6818 92 15 1 1
2 6818 12 1 1
3 6818 10 1 2
4 6818 11 1 3
5 6818 9 1 2
6 6818 8 2 1
預期輸出(帶移出循環)將是
test123
rn pds pv bl ag pg
1 6817 90 15 1 1
2 6817 90 12 1 1
3 6817 180 10 1 2
4 6817 540 10 1 3
5 6817 1080 11 1 2
1 6818 92 15 1 1
2 6818 92 12 1 1
3 6818 184 10 1 2
4 6818 552 11 1 3
5 6818 1104 9 1 2
6 6818 2208 8 2 1
PV可以是(PV值的乘積上一行)(AG)(PG)在 請看這個link
update b set b.pv=(a.pv*b.ag*b.pg)
from test123 a
left outer join test123 b
on b.pds=a.pds and b.rn=a.rn+1 and a.pds=b.pds;
話,可以上浮到SQL Server 2012(或更高版本)? – Amit
喜歡的SQL Server 2008阿米特 – asktosmart
我試試這個 '更新b 集b.projected_val =(a.projected_val * b.ag * b.pg) 從test123上b.pds一個 左外連接test123 B = A。 pds and b.rn = a.rn + 1;' – asktosmart