【发布时间】:2017-05-05 18:42:50
【问题描述】:
我有一张这样的桌子:
+----+--------+--------------------+
| 1 | Apple | Message 1 |
| 2 | Orange | Message two |
| 3 | Lime | Some data |
| 4 | Banana | More data |
| 5 | Lime | Boom. This is data |
| 6 | Pear | I'm on 6 row |
| 7 | Orange | Foo and Bar here |
| 8 | Banana | Remember Baz |
| 9 | Apple | Big fat juicy data |
| 10 | Lime | More values here |
| 11 | Pear | I'm almost empty |
+-------------+--------------------+
我有一些序列,比如:
(Banana, Apple, Orange, Lime, Pear)
所以我需要这样排序:
+----+--------+--------------------+
| 4 | Banana | More data |
| 1 | Apple | Message 1 |
| 2 | Orange | Message two |
| 3 | Lime | Some data |
| 6 | Pear | I'm on 6 row |
| 8 | Banana | Remember Baz |
| 9 | Apple | Big fat juicy data |
| 7 | Orange | Foo and Bar here |
| 5 | Lime | Boom. This is data |
| 11 | Pear | I'm almost empty |
| 10 | Lime | More values here |
+-------------+--------------------+
我怎样才能这样排序并且还有分页?
或者,一般来说,我需要对行进行排序,以便结果集中的每 N 行都是唯一的。
怎么做?
【问题讨论】:
-
这种逻辑是什么?我猜是因为
banana是第一个在 secuence 上应该是 1 -
@JuanCarlosOropeza 我想在一段时间内按页面列出 PHP 中的所有表行。而且我想要每一次传球都有一套独特的水果。请注意,水果的 ID 每次都不同,在现实世界中,我的表中有一些其他列,其中包含一些数据。
-
再解释一下逻辑是什么。
-
@JuanCarlosOropeza 想象一下其中包含唯一数据的某个表,其中包含一个带有一些重复值的列“Fruit”。我想逐页请求表格的行(比如一页上有 10 个结果),每页上都有唯一的“水果”列值。
-
@JuanCarlosOropeza 我已经编辑了表格来澄清它。
标签: mysql sorting unique sequence