with a1 as(
select 20 as a,'2022-01' as b
union all
select 30 as a,'2022-02' as b
union all
select 40 as a,'2022-03' as b
union all
select 50 as a,'2022-04' as b
),
b1 as (
select max(b) as b,sum(a) as a from a1 where b<='${参数}'
)
select a1.b,
case when a1.b<='${参数}' then b1.a
else a1.a
end as new_a
from a1
left join b1 on a1.b=b1.b