欧美一区二区三区,国内熟女精品熟女A片视频小说,日本av网,小鲜肉男男GAY做受XXX网站

mysql查詢第一條,mysql隨機查詢?nèi)舾蓷l數(shù)據(jù)的方法

錢諍諍2年前17瀏覽0評論
mysql查詢第一條,mysql隨機查詢?nèi)舾蓷l數(shù)據(jù)的方法?

1.隨機讀取連續(xù)多條記錄。經(jīng)過實踐,可以隨機讀取多條連續(xù)的數(shù)據(jù)記錄,里頭取值的一般都是主鍵ID來進行最大值、最小值的讀取:

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

2.隨機多條數(shù)據(jù)。以下兩種都是隨機讀取數(shù)據(jù),查詢數(shù)據(jù)速度、隨機范圍都基本相差不大

SELECT * FROM example_table WHERE id >= ((SELECT MAX(id) FROM example_table)-(SELECT MIN(id) FROM example_table)) * RAND() + (SELECT MIN(id) FROM example_table) LIMIT 5;

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