1. 程式人生 > >每人漲10%的工資,漲的前一共不超過5萬,從低工資往高工資的人漲,超過5W則停止漲,問漲的錢花了多少,多少人獲得了漲薪。

每人漲10%的工資,漲的前一共不超過5萬,從低工資往高工資的人漲,超過5W則停止漲,問漲的錢花了多少,多少人獲得了漲薪。

col case ID 技術 () 獲得 sum left number

技術分享圖片




;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則停止漲,問漲的錢花了多少,多少人獲得了漲薪。