A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

group query



 
 
Thread Tools Display Modes
  #1  
Old February 5th, 2010, 10:01 PM posted to microsoft.public.access.queries
Ian C
external usenet poster
 
Posts: 10
Default group query

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
  #2  
Old February 5th, 2010, 10:39 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default group query

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;

--
Build a little, test a little.


"Ian C" wrote:

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

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:33 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.