当前位置:Gxlcms > mysql > MYSQL的随机查询的实现方法

MYSQL的随机查询的实现方法

时间:2021-07-01 10:21:17 帮助过:33人阅读

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;

人气教程排行