declare @t table ( id int, SomeNumt int )insert into @tselect 1,10unionselect 2,12unionselect 3,3unionselect 4,15unionselect 5,23select * from @t8 r9 D; T) n5 c( J! v) S9 W
以上选择返回我以下。+ O- |* a* v+ u
id SomeNumt 102 123 34 1555 23 & A5 d* [# y; w4 ^& X
如何得到以下: 3 |0 u) I% G' A. w
; J! {1 ~# u8 z3 x- A6 i- r Y
id srome CumSrome1 10 10 102 12 2233 254 155 405 233 code] 7 c, E; C M2 u) _- d: h R
解决方案: [code]select t1.id,t1.SomeNumt,SUM(t2.SomeNumt) as sumfrom @t t1inner join @t t2 on t1.id >= t2.idgroup by t1.id,t1.SomeNumtorder by t1.id 2 v* i- O' d1 C5 a( w2 d2 i
输出; q+ P9 h+ e' k, v% _# q
| ID | SOMENUMT | SUM |-----------------------| 1 | 10 10 | 10 || 2 | 122 | 22 || 3 | 3 3 3 | 25 || 4 | 155 | 40 || 5 | 233 | 63 |+ k6 x6 g& c. D' F% F