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

首頁 > 數據庫 > SQL Server > 正文

SQL SERVER中對查詢結果隨機排序

2024-08-31 00:48:27
字體:
來源:轉載
供稿:網友


譯:sql server中對查詢結果隨機排序


randomly sorting query results
查詢結果隨機排序



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:

答:對結果記錄隨機排序,或隨機返回x條記錄,可以通過在select語句中使用rand函數來實現。但是rand函數在查詢中只生成一次,因此每一行都將得到相同的值。可以通過在order by子句中使用newid函數來對結果進行排序的方法來實現,代碼如下:

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

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


作者:water
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 克拉玛依市| 盱眙县| 紫云| 霞浦县| 古交市| 河间市| 信宜市| 富锦市| 阳泉市| 通化县| 安图县| 泗洪县| 龙口市| 普安县| 巴马| 和平区| 山西省| 扶沟县| 互助| 江口县| 饶阳县| 定陶县| 特克斯县| 宜昌市| 安宁市| 集贤县| 梓潼县| 达拉特旗| 泸水县| 且末县| 定西市| 开江县| 平武县| 和田县| 茂名市| 崇左市| 同仁县| 邓州市| 文山县| 文山县| 微山县|