Mysql 随机查询10条数据效率最快的查询方法

SELECT * FROM s_user WHERE id>= ((SELECT MAX(id) FROM s_user)-(SELECT MIN(id) FROM s_user)) * RAND() + (SELECT MIN(id) FROM s_user)  LIMIT 10
select * from articles where id>=(select floor(rand() * (select max(id) from articles))) order by id limit 10


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

// ...............................................................
SELECT
    *
FROM
    `t_topic`
WHERE
    id >= (
        SELECT
            floor(
                RAND() * (SELECT MAX(id) FROM `t_topic`)
            )
    )
ORDER BY
    id
LIMIT 10;
posted @ 2020-12-09 21:13  白云辉  阅读(188)  评论(0编辑  收藏  举报