本文介绍了如何以相反的顺序选择行(mysql)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何以相反的顺序选择行(DB MySQL)?
How can I select rows in reverse order (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的请求内容应该是怎样的?
What should the content of request to mysql be like?
在 30 分钟后编辑.
这是解决方案!例如,我检查了 drodil 的建议:
Editted at 30 minut later.
Here is solution!Some example, I checked drodil's suggestion so:
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)
Drodil,谢谢!
推荐答案
或者你可以不关心删除的结果,只需要得到给定 id (6) 之前的第四个:
Or you could do it without caring the deleted results, just get the fourth before the given id (6) by:
SELECT * FROM SomeTable WHERE id < 6 ORDER BY id DESC LIMIT 4,1
这篇关于如何以相反的顺序选择行(mysql)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!