SQL Server:
復制代碼 代碼如下:
Select TOP N * From TABLE Order By NewID()
view plaincopy to clipboardprint?
Select TOP N * From TABLE Order By NewID()
Select TOP N * From TABLE Order By NewID()
NewID()函數將創建一個 uniqueidentifier 類型的唯一值。上面的語句實現效果是從Table中隨機讀取N條記錄。
Access:
復制代碼 代碼如下:
Select TOP N * From TABLE Order By Rnd(ID)
view plaincopy to clipboardprint?
Select TOP N * From TABLE Order By Rnd(ID)
Select TOP N * From TABLE Order By Rnd(ID)
Rnd(ID) 其中的ID是自動編號字段,可以利用其他任何數值來完成,比如用姓名字段(UserName)
復制代碼 代碼如下:
Select TOP N * From TABLE Order BY Rnd(Len(UserName))
view plaincopy to clipboardprint?
Select TOP N * From TABLE Order BY Rnd(Len(UserName))
Select TOP N * From TABLE Order BY Rnd(Len(UserName))
MySql:
復制代碼 代碼如下:
Select * From TABLE Order By Rand() Limit 10
view plaincopy to clipboardprint?
Select * From TABLE Order By Rand() Limit 10
Select * From TABLE Order By Rand() Limit 10
postgreSQL:
復制代碼 代碼如下:
select * from glxt022 order by random() limit 5
view plaincopy to clipboardprint?
select * from glxt022 order by random() limit 5