group query

I

Ian C

I'm trying to create a query that gives me the average price of each product
based on the last 10 purchases.

The table is called "t_worksheet", with fields called
"buy_price_alt_currency" which represents the price, "processing_grade" which
represents the product and "collection_date" which represents the purchase
date.

I've been struggling with sub queries but can't get the results I need.
Please could somebody help.

Thanks

Ian
 
K

KARL DEWEY

I think this will work (UNTESTED) --
qryLastTen --
SELECT processing_grade, buy_price_alt_currency
FROM t_worksheet
WHERE t_worksheet.collection_date IN(SELECT TOP 10 [XX].collection_date FROM
t_worksheet AS [XX] WHERE [XX].processing_grade =
t_worksheet.processing_grade ORDER BY [XX].collection_date) DESC;

SELECT processing_grade, Sum([qryLastTen].buy_price_alt_currency)/10 AS
Average_Price
FROM qryLastTen
GROUP BY processing_grade;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top