mysql 随机取数据

2020-02-25  本文已影响0人  jiezzy

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;

上一篇 下一篇

猜你喜欢

热点阅读