表:T1:列:a(字符),列:b(字符),表:T2:列:b(字符),列:c(datetime),列:d(数值)。两表以b列关联,以a的值以及c列中存储的时间的年月作为分组条件,统计去年各月d的总量的SQL:
select month 月份 ,sum(ifnull(d,0)) 总量 from T1 , T2 where t1.b = t2.b group by t1.a , to_char(t2.c,'YYYY-mm') month where to_char(t2.c,"YYYY") = '2021'