请教下大家这个sql应该怎么写

请教大家, 上边数据通过怎样的sql可以生成红字格式的数据

661704348438_.pic_副本.png

评论区

bq

2024-01-05 12:00

select * from
(select pay_date,sum(pay_num) as pay_num,'合计' as pay_type from pay group by pay_date
union
select pay_date,pay_num,pay_type from pay) a
order by pay_date,pay_type