2

I'm trying to find the average figure for the last 10 rows in a database table:

select avg(Reading)
from Readings
Order By Rowid
desc limit 10;

This pulls the average of all entries in the table, not the last 10. I've tried all sorts of variations but can't get it to work.

CL.
  • 173,858
  • 17
  • 217
  • 259
PeteBradshaw
  • 111
  • 1
  • 5
  • 11

1 Answers1

2

Thanks for the super quick replies, I tried again and managed to type in the correct syntax this time in the From clause.

Here is the correct answer:

select avg(Reading)
from(select Reading
     from Readings
     Order By Rowid desc
     limit 10);
CL.
  • 173,858
  • 17
  • 217
  • 259
PeteBradshaw
  • 111
  • 1
  • 5
  • 11