Reputation: 2405
In my Database,
There is Data like this,
ID average_time
1 5
2 10
3 15
4 20
5 25
6 30
I create a query;
select total(average_time) from tbl_Timer order by id desc limit 5
It"s give the total of all values.
I want Total of LastFive Data,
How can i Do that?
Upvotes: 0
Views: 112
Reputation: 57583
Try this:
select sum(avtime) from
(SELECT average_time AS avTime
FROM tbl_Timer
ORDER BY id DESC LIMIT 5)
Upvotes: 2
Reputation: 721
If ID is sequential how about something like this
select sum(average_time) from data where id >= (select max(id)-4 from data);
Upvotes: 0