SELECT * FROM tablename AS r1 JOIN (SELECT ROUND(RAND() *(SELECT MAX(id)FROM tablename)) AS id) AS r2 WHERE r1.id >= r2.id ORDER BY r1.id ASC LIMIT 10000;
SELECT * FROM tablename ORDER BY rand() LIMIT 5
第一种速度比第二种快的多
SELECT * FROM tablename AS r1 JOIN (SELECT ROUND(RAND() *(SELECT MAX(id)FROM tablename)) AS id) AS r2 WHERE r1.id >= r2.id ORDER BY r1.id ASC LIMIT 10000;
SELECT * FROM tablename ORDER BY rand() LIMIT 5
第一种速度比第二种快的多