;with test(CID,money,NewAmount) as ( SELECT Row_Number() over ( order by money ) as CID
,money
,money *0.1 as NewAmount
FROM test107
) select b.CID , SUM(a.NewAmount ) sum_money, b.NewAmount
--distinct b.CID ,case when SUM(a.NewAmount ) > 50000 then 0 else b.NewAmount end as 涨薪
from test a
left outer join
test b
on a.CID <= b.CID
group by b.CID, b.NewAmount order by b.CID 原表与上述代码结果。