|
|
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
|
|
0
|
|
|
|
Reply
|
Utf
|
2/5/2010 10:01:01 PM |
|
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
|
|
0
|
|
|
|
Reply
|
Utf
|
2/5/2010 10:39:01 PM
|
|
|
1 Replies
197 Views
(page loaded in 0.045 seconds)
Similiar Articles: Group By Query - microsoft.public.access.queriesHello I'm struggling to explain this but here goes. I have a table which contains 6 fields which make up the location, 1 field which gives the t... Last records from a Group By query - microsoft.public.access ...I would like to write a query to find the last (most recent date) records only from two different fields. No problems using MAX in the ‘Date’ field, ... Group by date (month & week) in query - microsoft.public ...Hello, I have a query with the following data. completion date, part category, avgLT, countOrder Completion date in format of m/dd/yyyy and there ar... Query to group similar number combinations? - microsoft.public ...I'm trying to create a make-table query that will group records by two fields. The fields, named "Left" and "Right," both contain 4-digit identific... Can I use Select Top of every group in a Query? - microsoft.public ...I have a transaction table with a field named PersonID I want to select all the fields of the table with only the last 10 trans of each person sorted ... Add a sequence to a group of records in a query - microsoft.public ...This is the situation: I want to add a sequence to a group of records in a query that meet certain criteria. Example: GroupID AreaID ... Crosstab Query - Group by Month and Year - microsoft.public.access ...I've created a crosstab query that counts the number of calls per month. The call field only contains a date. I've used that field as the column h... Group by Range in Crosstab Query - microsoft.public.access.queries ...I have created a crosstab query which displays the number of days from referral to consult. I want to groups the days into ranges (0-14 days); (15... LDAP Query for All Groups and Membership - microsoft.public ...I am looking to query Active DIrectory in an environment with Windows 2000 DC's. Its a single domain environment. Currently I have a vbs file that p... Shortcuts to Queries in Custom Groups - microsoft.public.access ...When I add a query to a custom group, it is removed from the Unassigned Objects group, which is fine. But if I want to rename the query I right c... Using the GROUP BY Clause to Group SQL Query ResultsYou may use basic SQL queries to retrieve data from a database but this often doesn’t provide enough intelligence to meet business requirements. SQL also provides ... Group rows in query results (ADP) - Access - Office.comIf you want to create subtotals or show other summary information for subsets of a table, you create groups using an aggregate query. Each group summarizes the data ... SQL GROUP BY StatementThe GROUP BY Statement. The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns. How to: Group Rows in Query Results - Microsoft Corporation ...If you want to create subtotals or show other summary information for subsets of a table, you create groups using an aggregate query. Each group summarizes the data ... Consulting and coaching for more effective surveysQuery Group specializes in helping you develop, execute, and fine-tune surveys for: Customer satisfaction; Product development; Training needs and course evaluations 7/27/2012 2:38:29 PM
|
|
|
|
|
|
|
|
|