34,590
社区成员
发帖
与我相关
我的任务
分享
with cte
as
(select *,row_number over (partition by ygid order by id) as rn,count(1) over (partition by ygid) as qty_ygid
from table)
select *,case when rn=qty_ygid then 50-isnull(subtotal,0) else round(50*bfb,2) end as blje
from cte A
outter apply (select sum(round(50*bfb,2)) as subtotal from cte where A.ygid=ygid and rn<A.rn) as B