国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

如何隨機(jī)選取n條記錄或者對(duì)記錄作隨機(jī)排序?

2024-07-21 02:11:37
字體:
供稿:網(wǎng)友
. 如何得到隨機(jī)排序結(jié)果?

a. 要得到隨機(jī)排序的列,或者返回x條隨機(jī)選擇的列,你可以使用隨機(jī)數(shù)。但是rand函數(shù)在一個(gè)查詢中只能返回一個(gè)結(jié)果。你可以在nowid函數(shù)返回的列上做order by。請(qǐng)看示例:

select *
from northwind..orders
order by newid()

select top 10 *
from northwind..orders
order by newid()

這段話翻譯得真是費(fèi)勁,干脆不管原文,直接意譯了。
不過提醒大家注意,這種方法是要對(duì)整個(gè)表掃描,然后產(chǎn)生一個(gè)計(jì)算列再排序的,最好不要對(duì)大的表作這樣的操作,否則會(huì)很慢的。


q. how can i randomly sort query results?

a. to randomly order rows, or to return x number of randomly chosen rows, you can use the rand function inside the select statement. but the rand function is resolved only once for the entire query, so every row will get same value. you can use an order by clause to sort the rows by the result from the newid function, as the following code shows:

select *
from northwind..orders
order by newid()

select top 10 *
from northwind..orders
order by newid()


—sql server mvps
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 永平县| 东莞市| 紫金县| 兴义市| 灌云县| 连云港市| 抚州市| 铜梁县| 桃源县| 拉孜县| 东乡族自治县| 兴文县| 江安县| 璧山县| 旌德县| 凉城县| 岳阳县| 灵石县| 达日县| 郸城县| 山丹县| 湖北省| 定陶县| 新和县| 临西县| 尤溪县| 分宜县| 阳谷县| 平昌县| 灌云县| 连南| 惠来县| 塘沽区| 泸水县| 怀安县| 遂川县| 祁门县| 万州区| 琼结县| 西乡县| 东兰县|