这是表格:
name | id |
--------------------
jim | 267
jill | 267
larry| 268
tim | 269
riley| 267
joe | 301
pete | 301
gil | 110
shay : 701
bill | 301
所需的结果分为5个类别,不同的数字应分散在各个类别中,同时保持相同的数字:
cat 1 | cat 2 | cat 3 | cat 4 | cat 5
------------------------------------------------
jim 267 |Larry 268 |joe 301 |gil 110 |shay 701
jill 267 |tim 269 |pete 301| |
riley 267| |bill 301| |
所以基本上我想分组,尽可能分开不同的id。
答案 0 :(得分:0)
看起来你想要分组名称和id明智。如果是这样,那么它应该很简单,只需确保在分组时反转顺序
Select name,id from table group by id,name