美文网首页
mysql 随机取数据

mysql 随机取数据

作者: jiezzy | 来源:发表于2020-02-25 18:23 被阅读0次

SELECT * FROM table
WHERE id >= (SELECT floor( RAND() * ((SELECT MAX(id) FROM table)-(SELECT MIN(id) FROM table)) + (SELECT MIN(id) FROM table)))
ORDER BY id LIMIT 1;

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

相关文章

网友评论

      本文标题:mysql 随机取数据

      本文链接:https://www.haomeiwen.com/subject/tvcfchtx.html