MYSQL 中随机读取一条数据

SELECT * FROM res AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM res) - (SELECT MIN(id) FROM res)) + (SELECT MIN(id) FROM res)) AS id) AS t2 WHERE t1.id >= t2.id ORDER BY t1.id LIMIT 1;

 

select * FROM `res` AS t1 JOIN(SELECT ROUND(RAND()*((SELECT MAX(id)FROM `res` )-(SELECT MIN(id) FROM `res`))+(SELECT MIN(id) FROM `res`)) AS id )AS t2
WHERE t1.id>=t2.id ORDER BY t1.id LIMIT 1;

 

参考:http://blog.csdn.net/testcs_dn/article/details/10149293

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。