[thelist] get avg of last 3 records in SQL
listman at hazard0us.org
listman at hazard0us.org
Fri Nov 8 03:28:01 CST 2002
If your database supports the TOP syntax this should do it :
select avg(xSteps.steps)
from
(select top 3 steps from tblSteps
order by updated_date desc) xSteps
xSteps is a an alias for a pseudo table that has the 3 latest updated
records.
we get the last 3 updated records by ordering the table in descending order
of date
(which ensures that the latest records come on top of the result set)
and then we apply the top 3 operator to return only the last 3 records...
HTH
ashok
------
Ashok Hariharan
http://www.unganisha.org
------
More information about the thelist
mailing list