先列转行 再日期过滤 汇总 可参考 select 其他字段,sum(mon_value) from( select 表其他字段, unnest(array[ 年份字段||'01', 年份字段||'02', 年份字段||'03', 年份字段||'04', 年份字段||'05', 年份字段||'06', 年份字段||'07', 年份字段||'08', 年份字段||'09', 年份字段||'10', 年份字段||'11', 年份字段||'12' ]) as year_mon, unnest(array[ JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER ]) as mon_value from 表名)tt where year_mon between 开始月 and 结束月 group by 其他字段
|