mysql> select DISTINCT number, id from table order by rand()
+------+------------+
| id | number |
+------+------------+
| 2 | 4 |
| 1 | 3 |
| 4 | 3 |
| 3 | 4 |
+------+------------+
我需要得到类似的东西
+------+------------+
| id | number |
+------+------------+
| 2 | 4 |
| 4 | 3 |
+------+------------+
刷新
+------+------------+
| id | number |
+------+------------+
| 3 | 4 |
| 1 | 3 |
+------+------------+
刷新....
答案 0 :(得分:0)
SELECT
( SELECT tt.id
FROM tableX AS tt
WHERE tt.number = t.number
ORDER BY RAND()
LIMIT 1
) AS id,
number
FROM
tableX AS t
GROUP BY
number ;