Need help on query - average of most recent 25 results

  • Thread starter Thread starter Philip Lo
  • Start date Start date
P

Philip Lo

Hi,

I have a table with 3 columns, col 1 is date time, col 2 is text, and col 3
is number. Is it possible to have one single query that calculates the
average of 3 for col 3 (selection of 3 rows is based on those with most
recent time stamp in col 1) group by col 2 ?

Example:
------------------
col 1, col 2, col 3
------------------
1 Oct 2005, A01, 20;
2 Oct 2005, A01, 25;
3 Oct 2005, A01, 30;
4 Oct 2005, A01, 35;
5 Oct 2005, A02, 40;
6 Oct 2005, A02, 45;
7 Oct 2005, A02, 50;
8 Oct 2005, A02, 55;

After query:
-------------------------------------------
Average of most recent 3 result, col 2
-------------------------------------------
(25+30+35)/3=30, A01;
(45+50+55)/3=50, A02;

Thanks....

regards,
Philip
 
Philip

Define "most recent". Based on the data example you posted, Access will
have no way to know which are the 3 most recent.

Regards

Jeff Boyce
<Office/Access MVP>
 
man, i should charge you for making me think

=P

select (sum(col3)-max(col3))/(count(*)-1) from table1 group by col2

your date column might have to be indexed asc not sure didnt test

Michael Evanchik
www.MichaelEvanchik.com
 
Back
Top