I made a decision with this SQL. I need the rows to be the number of classes, and the columns to be total for each class unit by month, so the first column is the sum of the row, and each ocher column is the total of each month, and the last row is the total of the complete column by month.
Good luck.
Select DS.Cla, Sum(case when (Extract(year from DS.Data) =:intYear) then DS.PRE else 0 end) as ToTal, Sum(case when (Extract(month from DS.Data) =1) then DS.PRE else 0 end) as Jan, Sum(case when (Extract(month from DS.Data) =2) then DS.PRE else 0 end) as FEV, Sum(case when (Extract(month from DS.Data) =3) then DS.PRE else 0 end) as MAR, Sum(case when (Extract(month from DS.Data) =4) then DS.PRE else 0 end) as ABR, Sum(case when (Extract(month from DS.Data) =5) then DS.PRE else 0 end) as MAI, Sum(case when (Extract(month from DS.Data) =6) then DS.PRE else 0 end) as JUN, Sum(case when (Extract(month from DS.Data) =7) then DS.PRE else 0 end) as JUL, Sum(case when (Extract(month from DS.Data) =8) then DS.PRE else 0 end) as AGO, Sum(case when (Extract(month from DS.Data) =9) then DS.PRE else 0 end) as SETE, Sum(case when (Extract(month from DS.Data) =10) then DS.PRE else 0 end) as OUT, Sum(case when (Extract(month from DS.Data) =11) then DS.PRE else 0 end) as NOV, Sum(case when (Extract(month from DS.Data) =12) then DS.PRE else 0 end) as DEZ from Dados DS Where DS.Cla > 0 And Extract(Year from DS.Data) = :intYear group by DS.CLA Union All Select 0*count(DS.cla), 0*count(DS.cla), Sum(case when (Extract(month from DS.Data) =1) then DS.PRE else 0 end) as JAN, Sum(case when (Extract(month from DS.Data) =2) then DS.PRE else 0 end) as FEV, Sum(case when (Extract(month from DS.Data) =3) then DS.PRE else 0 end) as MAR, Sum(case when (Extract(month from DS.Data) =4) then DS.PRE else 0 end) as ABR, Sum(case when (Extract(month from DS.Data) =5) then DS.PRE else 0 end) as MAI, Sum(case when (Extract(month from DS.Data) =6) then DS.PRE else 0 end) as JUN, Sum(case when (Extract(month from DS.Data) =7) then DS.PRE else 0 end) as JUL, Sum(case when (Extract(month from DS.Data) =8) then DS.PRE else 0 end) as AGO, Sum(case when (Extract(month from DS.Data) =9) then DS.PRE else 0 end) as SETE, Sum(case when (Extract(month from DS.Data) =10) then DS.PRE else 0 end) as OUT, Sum(case when (Extract(month from DS.Data) =11) then DS.PRE else 0 end) as NOV, Sum(case when (Extract(month from DS.Data) =12) then DS.PRE else 0 end) as DEZ from Dados DS Where DS.Cla > 0 And Extract(Year from DS.Data) = :intYear
source share