Special average calculation

mazides

New member
Local time
Today, 03:21
Joined
Oct 16, 2013
Messages
1
Hello,

i use access 2007 and i have a table with customer details and their purchases. I need a query to calculate the average value of the last 5 purchases per customer, irrespective of the day those purchases took place. That is, one customer may have made his last 5 purchases between lets say 15/09/13 and 25/09/13, while another may have made them one month earlier.

Thanks
 
Something like this will do what you need:
Code:
SELECT Avg(ctValue) AS AvgVolume FROM (SELECT TOP 5 ctValue FROM tCustomer WHERE ctId=2 ORDER BY ctDate DESC);
The inner query selects the top 5 items for customer 2 (in this case), from the most recently dated records. The outer query takes the average of these results.
 

Users who are viewing this thread

Back
Top Bottom