I have a table record like below:-
my_table
id | rating | description
1 | 0.0 | bed
2 | 1.0 | good
3 | 0.0 | bed
4 | 1.0 | good
5 | 0.0 | bed
6 | 0.0 | bed
7 | 0.0 | bed
Now I shorted this table by rating and I got following result.
(Query : SELECT * FROM my_table ORDER BY rating DESC)
Result table
id | rating | description
2 | 1.0 | good
4 | 1.0 | good
1 | 0.0 | bed
==> 3 | 0.0 | bed
5 | 0.0 | bed
6 | 0.0 | bed
7 | 0.0 | bed
Now I want previous record of id = 3.
expected result
id | rating | description
1 | 0.0 | bed
How can I achieve it. within single mysql query?
Please help me.
解决方案
Use this:
SELECT * FROM my_table ORDER BY rating DESC LIMIT 2,1