假設我有一個MySQL表:有趣MYSQL益智T20
ID - int, auto-increment
Num - int
Num是插入行插入表之前隨機選擇的1和100之間的隨機整數。假設我在表中有1000個條目。 例如:
1,65
2,23
3,87
4,99
5,75
6,45
etc.
由此看來,一個人怎麼能獲得前20 NUM值的id值?
假設我有一個MySQL表:有趣MYSQL益智T20
ID - int, auto-increment
Num - int
Num是插入行插入表之前隨機選擇的1和100之間的隨機整數。假設我在表中有1000個條目。 例如:
1,65
2,23
3,87
4,99
5,75
6,45
etc.
由此看來,一個人怎麼能獲得前20 NUM值的id值?
我猜你希望發生最頻繁的隨機數的所有ID:
select Num, COUNT(id) as cnt, GROUP_CONCAT(id)
from yourtable
group by Num
order by cnt desc
limit 20
select id
from table
order by Num desc
limit 0, 20
SELECT ID FROM Table ORDER BY Num DESC LIMIT 20