order by newid 隨機查詢

2021-05-23 06:59:23 字數 1157 閱讀 1019

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

oracle SQL sample 隨機抽樣查詢

建立測試表 sql create table t1 x int table created.插入10000行資料 sql begin 2 for i in 1.10000 loop 3 insert into t1 values i 4 end loop 5 end 6 pl sql procedu...

mysql隨機查一條

mysql select rand rand 0.048264377795406 1 row in set 0.00 sec mysql select rand rand 0.557701361885016 1 row in set 0.00 sec mysql select rand rand 0...

MySQL資料庫中如何使用rand隨機查詢記錄

以下的文章主要介紹的是mysql使用rand 隨機查詢記錄效率測試,我們大家一直都以為mysql資料庫隨機查詢的幾條資料,就用以下的東東,其實其實際效率是十分低的,以下就是文章的主要內容。1.select from table order by rand limit 5 就可以了。但是真正測試一下才...