Hi Terri,
I guess from your messages you're talking about calendar years (e.g. as
opposed to financial). If that's the case, you can do what you want by
using the Year() function and a series of three queries.
(1) Get sum ID Amount Sum for every year in the table:
SELECT Transactions.ID, Year([TransactionDate]) AS TransactionYear,
Sum(Transactions.Amount) AS YearAmount
FROM Transactions
GROUP BY Transactions.ID, Year([TransactionDate]);
(2) Get the latest year for each ID from the query above:
SELECT qry1_year_sums_all.ID, Max(qry1_year_sums_all.TransactionYear) AS
MaxTransactionYear
FROM qry1_year_sums_all
GROUP BY qry1_year_sums_all.ID;
(3) Join the above queries to get the yearly sums for the latest years
only:
SELECT qry1_year_sums_all.*
FROM qry2_max_year INNER JOIN qry1_year_sums_all ON
(qry1_year_sums_all.TransactionYear = qry2_max_year.MaxTransactionYear)
AND (qry2_max_year.ID = qry1_year_sums_all.ID);
Let me know if you have any trouble with these queries.
Cheers,
------------
LoopyNZ
------------
=====================
Original Message:
I have a table called Transactions with 3 fields: ID, Date, and Amount.
Each
ID can have multiple transactions in one particular year. An ID might
not
have had any transactions in recent years.
For each ID I would like to sum all the transactions for the most recent
year in which one or more transactions have occurred.
Thanks for any help and for all previous help.
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!