I have a table of Waste IDs, with a relationship with a second table of Waste Weights:
WasteIDs
WasteWeights:
I want to look up the last 10 wasteweights for an id, and get an average.
So I can do:
to get the last 10, but this only works when i put in particular IDs, I want the average of the top 10 for each ID so I can have it as part of a report
so the final datasheet will be like:
Any ideas? Could it be done with multiple queries maybe?
WasteIDs
Code:
id name 1. Paper 2. Cardboard 3. Cans
Code:
Id date kg 1. 1/1/09 12 1. 1/2/09 24 2. 1/1/09 2
So I can do:
Code:
SELECT avg(weight) FROM (SELECT TOP 10 weight FROM wasteweights WHERE id=1 ORDER BY [date] DESC)
so the final datasheet will be like:
Code:
Id Avg 1. 18 2. 2
Comment