效率极差的一种办法:

select * from 表名 order by rand( ) limit 1;  //此处的1就是取出数据的条数

高效写法

SELECT * FROM user  WHERE userId >= ((SELECT MAX(userId) FROM user )-(SELECT MIN(userId) FROM user )) * RAND() + (SELECT MIN(userId) FROM user )  LIMIT 5
Logo

更多推荐