如何以相反的顺序选择行(mysql)

Yur*_*nko 14 mysql sql

如何以相反的顺序选择行(DB MySQL)?

For example,
 I have a table with 12 rows (fields: id,location), I want select -4th row before a row with id = 6,
 i.e. wanted row will have id = 'not necessarily 2',
  but there is condition - where table.location='some_location'.
Run Code Online (Sandbox Code Playgroud)

请求mysql的内容应该是什么样的?




30分钟后编辑.
这是解决方案!举个例子,我检查了drodil的建议:

mysql> select * from subscrs where id < 100000 order by id desc limit 4;
+-------+--------+-----------+-------+
| uid   | subscr | event     | id    |
+-------+--------+-----------+-------+
|  5307 |   5123 | feed_news | 99999 |
| 25985 |   5211 | feed_news | 99998 |
| 15123 |    130 | feed_news | 99997 |
| 28368 |  19497 | feed_news | 99996 |
+-------+--------+-----------+-------+
4 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)

Drodil,谢谢!

dro*_*dil 24

或者您可以在不关心已删除的结果的情况下执行此操作,只需在给定的id(6)之前获取第四个:

SELECT * FROM SomeTable WHERE id < 6 ORDER BY id DESC LIMIT 4,1
Run Code Online (Sandbox Code Playgroud)