Hi all, I have the following query
This returns data like this
FieldCode FieldName OMApplicationMonth SumOfTotalNAppliedByOM
-2014214583 Seven Acres Jul-06 99
-2014214583 Seven Acres Apr-09 60
-2014214583 Seven Acres Feb-11 99
-2014214583 Seven Acres Mar-13 91
-1833868285 Earth Down Apr-07 165
-1794524754 Stable Down Dec-04 111
-1794524754 Stable Down Dec-07 24
-1794524754 Stable Down Feb-08 39
-1794524754 Stable Down Aug-12 50
-1671606118 Lane Field Jan-08 42
-1671606118 Lane Field Feb-08 27
-1671606118 Lane Field May-08 50
-1671606118 Lane Field Jun-08 39
-1671606118 Lane Field Dec-08 88
-1671606118 Lane Field May-09 60
-1671606118 Lane Field Feb-12 91
Sorry about the formatting
I need to create a query which gives a rolling previous 12 months sum of SumOfTotalNAppliedByOM so looking at the Feb-12 entry for Lane Field the total would be 91 but for the May-09 entry the total would be 39+88+60 = 187.
Can anyone help with this?
As always thank you for any suggestions.
Code:
SELECT tblFieldDetails.FieldCode, tblFieldDetails.FieldName, tblOMApplications.OMApplicationMonth, Sum(qryrpt10FTotalOMNP1.TotalNAppliedByOM) AS SumOfTotalNAppliedByOM
FROM (qrySLTReport INNER JOIN tblFieldDetails ON qrySLTReport.FarmAccountNumber = tblFieldDetails.FarmAccountNumber) INNER JOIN (tblCropping INNER JOIN (tblOMApplications LEFT JOIN qryrpt10FTotalOMNP1 ON tblOMApplications.OMApplicationIndex = qryrpt10FTotalOMNP1.OMApplicationIndex) ON tblCropping.CroppingNumber = tblOMApplications.CroppingNumber) ON tblFieldDetails.FieldCode = tblCropping.FieldCode
GROUP BY tblOMApplications.IncludeInReports, tblFieldDetails.FieldCode, tblFieldDetails.FieldName, tblOMApplications.OMApplicationMonth
HAVING (((tblOMApplications.IncludeInReports)=Yes));
This returns data like this
FieldCode FieldName OMApplicationMonth SumOfTotalNAppliedByOM
-2014214583 Seven Acres Jul-06 99
-2014214583 Seven Acres Apr-09 60
-2014214583 Seven Acres Feb-11 99
-2014214583 Seven Acres Mar-13 91
-1833868285 Earth Down Apr-07 165
-1794524754 Stable Down Dec-04 111
-1794524754 Stable Down Dec-07 24
-1794524754 Stable Down Feb-08 39
-1794524754 Stable Down Aug-12 50
-1671606118 Lane Field Jan-08 42
-1671606118 Lane Field Feb-08 27
-1671606118 Lane Field May-08 50
-1671606118 Lane Field Jun-08 39
-1671606118 Lane Field Dec-08 88
-1671606118 Lane Field May-09 60
-1671606118 Lane Field Feb-12 91
Sorry about the formatting
I need to create a query which gives a rolling previous 12 months sum of SumOfTotalNAppliedByOM so looking at the Feb-12 entry for Lane Field the total would be 91 but for the May-09 entry the total would be 39+88+60 = 187.
Can anyone help with this?
As always thank you for any suggestions.