几种常见数据库的随机排序函数

红薯 发布于 2010/05/04 11:27
阅读 1K+
收藏 2

MySQL:

SELECT * FROM TABLE ORDER BY RAND() LIMIT 1;

SQLite:

SELECT * FROM TABLE ORDER BY RANDOM() LIMIT 1;

PostgreSQL:

SELECT * FROM TABLE ORDER BY RANDOM() LIMIT 1;

Oracle:

select * from table order by dbms_random.value;

SQL Server:

SELECT * FROM Northwind..Orders ORDER BY NEWID()

DB2:

SELECT column, RAND() as IDX
FROM table
ORDER BY IDX FETCH FIRST 1 ROWS ONLY

加载中
返回顶部
顶部