MYSQL查询随机几条记录

1、select * from $table where  id> rand()*(select max(id) from $table) limit 5

2、SELECT * FROM $table AS r1 JOIN (SELECT ROUND(RAND() * (SELECT MAX(id) FROM $table)) AS id) AS r2 WHERE r1.id >= r2.id ORDER BY r1.id ASC LIMIT 10

方法2效率更高。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

😉😐😡😈🙂😯🙁🙄😛😳😮:mrgreen:😆💡😀👿😥😎😕