mysql随机获取数据

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;

 

posted @ 2018-03-26 16:11  一个88Er  阅读(147)  评论(0编辑  收藏  举报