The SQL below is functioning when it comes to summarize ONE month. My problem is that I want the sum of three previous month, i.e.

TOTAL SUM of
(present month (SUM (A1.SA_DEB_M_SE_HBO - A1.SA_KRE_M_SE_HBO)
+ previous month (SUM (A1.SA_DEB_M_SE_HBO - A1.SA_KRE_M_SE_HBO)
+ present month -2 (SUM (A1.SA_DEB_M_SE_HBO - A1.SA_KRE_M_SE_HBO))

The month of interest is located in DB2.EMIIHB02 A3

How do I accomplish this!??!
/Maria


SELECT A1.MONTH
,A1.ORGNR_DB
,A2.KOD_SEKTOR
,A2.KAT_EGARE
,A2.KOD_LAND
,A2.ID_GRUPP_PROD || A2.ID_STR
,A1.ID_KTO_HBO
,A2.ID_VALUTA
,A2.ID_BELOPP_TYP
,A2.ID_LOPTID
,A3.ID_HBO_DATUM
,SUM (A1.SA_DEB_M_SE_HBO - A1.SA_KRE_M_SE_HBO)

FROM DB2.STYIV011 A1,
DB2.EMIISA01 A2,
DB2.EMIIHB02 A3

WHERE A1.MONTH = A3.MONTH
AND A1.DAT_OVERF_HBO = A3.ID_HBO_DATUM
AND A1.ORGNR_DB = A3.BANKID
AND A1.ID_KODOVERF_HBO <> '2'
AND A2.ID_GRUPP_PROD = 'HBO'
AND A2.ID_MATVARDE_TYP = 'MV022'
AND A2.KOD_BANKTILLH = '2'
AND A1.ORGNR_DB < 8999
AND A1.ID_KTO_HBO BETWEEN A2.PRODID_FROM AND A2.PRODID_TOM

GROUP BY A1.MONTH
,A1.ORGNR_DB
,A2.KOD_SEKTOR
,A2.KAT_EGARE
,A2.KOD_LAND
,A2.ID_GRUPP_PROD
,A2.ID_STR
,A1.ID_KTO_HBO
,A2.ID_VALUTA
,A2.ID_BELOPP_TYP
,A2.ID_LOPTID
,A3.ID_HBO_DATUM
HAVING SUM (A1.SA_DEB_M_SE_HBO - A1.SA_KRE_M_SE_HBO) ^= 0
;