如何以相反的顺序选择行(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'.
对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)
德罗迪尔,谢谢!
或者,您可以在不关心删除结果的情况下执行此操作,只需通过以下方式获得给定id(6)之前的第四个:
SELECT * FROM SomeTable WHERE id < 6 ORDER BY id DESC LIMIT 4,1