我有一個包含不同類別的表。是否有可能從每個類別返回兩個隨機行?SQL:從每個類別獲取2行
我的表:
-----------------------------
| ID | CATEGORY |
-----------------------------
| 1 | PINK |
| 2 | GREEN |
| 3 | PINK |
| 4 | GREEN |
| 5 | BLUE |
| 6 | BLUE |
| 7 | BLUE |
| 8 | PINK |
| 9 | GREEN |
-----------------------------
我要輸出什麼:
-----------------------------
| ID | CATEGORY |
-----------------------------
| 1 | PINK |
| 8 | PINK |
| 2 | GREEN |
| 4 | GREEN |
| 6 | BLUE |
| 7 | BLUE |
-----------------------------
是的。這是可能的http://stackoverflow.com/questions/19412/how-to-request-a-random-row-in-sql – zod
^這是一個不同的問題 – user2217162
定義「隨機」 – Woot4Moo