类似这样,数据处理成多列。。然后按顺序放就行了

select
月份字段,
sum(case when year_code ='2022年' then 金额 else null end) as 2022年数据,
sum(case when year_code ='2023年' then 金额 else null end) as 2023年数据,
sum(case when year_code ='2024年' then 金额 else null end) as 2024年数据
from 表名称
group by 月份字段