MySql 获取数据表中随机一条数据
通过sql语句获取数据表中的随意一条数据
-- rand() 获取0到1之间的随机浮点数 -- ((select max(id) from test) - (select min(id) from test)) * rand() 获取到随机数 -- + (select min(id) from test) 保证id为 最小ID与最大ID之间的数 select * from test where id >= ((select max(id) from test) - (select min(id) from test)) * rand() + (select min(id) from test) limit 1; -- 或者 select * from test where id >= ((select max(id) from test) - (select min(id) from test)) * rand() and id > (select min(id) from test) limit 1;