Is it possible to make a total sum of the sum of present month + (present month - 1)?
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!??!
,A2.ID_GRUPP_PROD || A2.ID_STR
,SUM (A1.SA_DEB_M_SE_HBO - A1.SA_KRE_M_SE_HBO)
FROM DB2.STYIV011 A1,
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
HAVING SUM (A1.SA_DEB_M_SE_HBO - A1.SA_KRE_M_SE_HBO) ^= 0
I'm having some trouble reading your field names, but I felt I should throw this out anyway:
SELECT Sum(fieldOne - fieldTwo)
WHERE Month(YourDateField) > Month(Date())-3;
An example of the data you're starting with and the data you want to get from your query might be helpful in clarifying the problem.
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL