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

mysql 查詢當(dāng)前數(shù)據(jù),mysql隨機(jī)查詢?nèi)舾蓷l數(shù)據(jù)的方法

江奕云2年前18瀏覽0評論
mysql 查詢當(dāng)前數(shù)據(jù),mysql隨機(jī)查詢?nèi)舾蓷l數(shù)據(jù)的方法?

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

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.隨機(jī)多條數(shù)據(jù)。以下兩種都是隨機(jī)讀取數(shù)據(jù),查詢數(shù)據(jù)速度、隨機(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;