一、随机查询一条数据
SELECT * FROM `table` AS t1
JOIN (
SELECT ROUND(RAND() * ((SELECT MAX(id) FROM `table`)-(SELECT MIN(id) FROM `table`))+(SELECT MIN(id) FROM `table`)) AS id
) AS t2
WHERE t1.id >= t2.id
ORDER BY t1.id LIMIT 1;
二、随机查询多条数据
SELECT * FROM `table` AS t1
JOIN (
SELECT ROUND(RAND() * ((SELECT MAX(id) FROM `table`)-(SELECT MIN(id) FROM `table`))+(SELECT MIN(id) FROM `table`)
) AS id
from `table` limit 50) AS t2 on t1.id=t2.id
ORDER BY t1.id;
标签:relevant,查询,blog,随机,MySQL,table,t1,id,SELECT From: https://www.cnblogs.com/mask-xiexie/p/16779997.html