Query second (n-th) last value?

Is it possible to query only second (n-th) last value from a measurement?

A bit ugly, but should work:

Select value from (select value from table where whatever order by time desc
limit 2) order by time limit 1;

Antony.

If I am running this query then I am getting an error that

subqueries must be ordered in the same direction as the query itself

Meh. I don’t think I have an alternative idea, then. Hopefully someone else
has.

Antony.

After much hit and trial, I found a way
To get 2nd last value:
SELECT st FROM (SELECT value as st FROM Value WHERE whatever ORDER BY time DESC LIMIT 2 OFFSET 1) ORDER BY time DESC LIMIT 1

To get 3rd last value:
SELECT st FROM (SELECT value as st FROM Value WHERE whatever ORDER BY time DESC LIMIT 3 OFFSET 2) ORDER BY time DESC LIMIT 1