复制代码 代码如下:
SELECT * FROM tablename ORDER BY RAND() LIMIT 1
复制代码 代码如下:
SELECT *
FROM 'table' AS t1 JOIN (SELECT ROUND(RAND() * (SELECT MAX(id) FROM 'table')) AS id) AS t2
WHERE t1.id >= t2.id
ORDER BY t1.id ASC LIMIT 5;
复制代码 代码如下:
SELECT *
FROM 'table'
WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM 'table' )
ORDER BY id LIMIT 1;
复制代码 代码如下:
SELECT * FROM 'table'
WHERE id >= (SELECT floor(RAND() * (SELECT MAX(id) FROM 'table')))
ORDER BY id LIMIT 1;
复制代码 代码如下:
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(
# 最小值 + (1 至 最小与最大值差)
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;
复制代码 代码如下:
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 10;
新闻热点
疑难解答