PHP小丑 发表于 2022-1-27 21:16:59

数据库查询排序使用随机排序结果示例(Oracle/MySQL/MS SQL Server)

Oracle查询结果集,随机排序

select * from table1 order by dbms_random.value();

MySQL随机查询出一条记录:

-- 下面的查询语句效率高,不要使用 SELECT * FROM table1 ORDER BY rand() LIMIT 1 来查询 SELECT * FROM table1 WHERE id=(SELECT id FROM table1 ORDER BY rand() LIMIT 1)

查询结果集,随机排序

SELECT * FROM table1 ORDER BY rand()

MS SQL Server

SELECT *
FROM Northwind Orders
ORDER BY NEWID()
SELECT TOP 10 *
FROM Northwind Orders
ORDER BY NEWID()


https://www.uoften.com/dbs/oracle/20180415/73081.html
页: [1]
查看完整版本: 数据库查询排序使用随机排序结果示例(Oracle/MySQL/MS SQL Server)