order by newid() 各類數據庫隨機查詢的辦法。本站提示廣大學習愛好者:(order by newid() 各類數據庫隨機查詢的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是order by newid() 各類數據庫隨機查詢的辦法正文
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