(轉)隨機選擇行的SQL語句? ORACLE SQLSERVER ECT.

mahanso發表於2010-12-14

MySQL:

SELECT column FROM table
ORDER BY RAND()
LIMIT 1

PostgreSQL:

SELECT column FROM table
ORDER BY RANDOM()
LIMIT 1

Microsoft SQL Server:

SELECT TOP 1 column FROM table
ORDER BY NEWID()

IBM DB2

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

Oracle:

SELECT column FROM
( SELECT column FROM table
ORDER BY dbms_random.value )
WHERE rownum = 1

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12272958/viewspace-681770/,如需轉載,請註明出處,否則將追究法律責任。

相關文章