mysql合并 UNION ALL 行以删除 NULL 值

我想要实现不同年份,同一月份的数据相对应,把空行删掉,尝试使用了聚合函数max,和sum,也参考了https://stackoverflow.com/questions/57848916/eliminating-null-values-from-the-union-set-operators 这篇文章,发现只适合于单行,多行对多行就不太适用,请问有什么好办法么?

img

img

因为题主想要同月份的放到一行里面,这个实际上就是一个左连接,只需要加多一个虚拟的字段,这个字段的值需要把日期中的月份截取出来,然后通过左连接把月份对应上就好了,比如 select t1.xxx, t2.xxx from (select substring(yearmonth, 6, 2) as mon, t.* from table where 2023年数据 t) t1 left join (select substring(yearmonth, 6, 2) as mon, t.* from table where 2022年数据 t) t2 on t1.mon = t2.mon