G
Guest
I have a table silimar to one below but with a lot of extra variables.
Essentially, what I need to calculate is the sum of amount for the recent
three months for each month.
ID Month Amount
1 200606 100
2 200607 25
3 200608 34
4 200609 54
5 200610 56
6 200611 76
7 200612 123
8 200701 56
9 200702 78
10 200703 56
The additional column I would need from the column above is as follows:
ID Month Amount TR3_Amount
1 200606 100 100
2 200607 25 125
3 200608 34 159
4 200609 54 113
5 200610 56 144
6 200611 76 186
7 200612 123 255
8 200701 56 255
9 200702 78 257
10 200703 56 190
I was able to get this column using the following query:
SELECT a.ID, a.Month, a.Amount, sum(b.Amount) AS TR3_Amount
FROM TR3 AS a, TR3 AS b
WHERE a.ID>=b.ID and a.ID<b.ID+3
GROUP BY a.ID, a.Month, a.Amount;
This would perfectly serve my purpose if my table was smaller.
Unfortunately, with the 30,000 records I have in my table, it takes too long
for Access to calculate. Does anyone have a different idea?
I am a beginner in Access and don't know much VBA. Is there any other
solution to this problem using SQL?
Thanks for all your help.
Nikesh
Essentially, what I need to calculate is the sum of amount for the recent
three months for each month.
ID Month Amount
1 200606 100
2 200607 25
3 200608 34
4 200609 54
5 200610 56
6 200611 76
7 200612 123
8 200701 56
9 200702 78
10 200703 56
The additional column I would need from the column above is as follows:
ID Month Amount TR3_Amount
1 200606 100 100
2 200607 25 125
3 200608 34 159
4 200609 54 113
5 200610 56 144
6 200611 76 186
7 200612 123 255
8 200701 56 255
9 200702 78 257
10 200703 56 190
I was able to get this column using the following query:
SELECT a.ID, a.Month, a.Amount, sum(b.Amount) AS TR3_Amount
FROM TR3 AS a, TR3 AS b
WHERE a.ID>=b.ID and a.ID<b.ID+3
GROUP BY a.ID, a.Month, a.Amount;
This would perfectly serve my purpose if my table was smaller.
Unfortunately, with the 30,000 records I have in my table, it takes too long
for Access to calculate. Does anyone have a different idea?
I am a beginner in Access and don't know much VBA. Is there any other
solution to this problem using SQL?
Thanks for all your help.
Nikesh