每人涨10%的工资,涨的前一共不超过5万,从低工资往高工资的人涨,超过5W则停止涨,问涨的钱花了多少,多少人获得了涨薪。-LMLPHP


;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 原表与上述代码结果。

每人涨10%的工资,涨的前一共不超过5万,从低工资往高工资的人涨,超过5W则停止涨,问涨的钱花了多少,多少人获得了涨薪。-LMLPHP

05-11 17:32