如何以相反顺序选择行(DB MySQL)?如何以相反顺序选择行(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的请求内容应该是什么样的?
Editted在30 minut以后。
这里是解决方案! 一些例子,我查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)
Drodil,谢谢!
我不确定你想通过选择一个ID为4以下的ID所提供的ID来实现。 请提供更多详细信息,因为我认为您的问题可能存在更合适的解决方案。 – aaroncatlin 2012-03-06 11:09:15
你能澄清一下你的问题吗,也许你可以通过包括一些样本数据以及你想如何定购?目前,我不明白你想要做什么。 – 2012-03-06 11:10:15
如果你的ID是自动递增的,并且有人已经删除了你的案例中的行ID 2,那么会发生什么?如果提供的id是2,会发生什么情况,因此之前的四行会有id -1(不存在)? – 2012-03-06 11:13:11