欧美久久天天综合香蕉伊,h片在线免费观看,九九欧美,欧美1区2区3区,日本在线不卡一区,国产视频久久久,91久久久久久久

2023信創(chuàng)獨(dú)角獸企業(yè)100強(qiáng)
全世界各行各業(yè)聯(lián)合起來(lái),internet一定要實(shí)現(xiàn)!

SQL SERVER中對(duì)查詢(xún)結(jié)果隨機(jī)排序

2004-02-11 eNet&Ciweek

  Randomly Sorting Query Results

  查詢(xún)結(jié)果隨機(jī)排序   

  Q. How can I randomly sort query results?

  問(wèn):怎樣才能對(duì)查詢(xún)結(jié)果隨機(jī)排序?  

  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:  

  答:對(duì)結(jié)果記錄隨機(jī)排序,或隨機(jī)返回X條記錄,可以通過(guò)在SELECT語(yǔ)句中使用RAND函數(shù)來(lái)實(shí)現(xiàn)。但是RAND函數(shù)在查詢(xún)中只生成一次,因此每一行都將得到相同的值??梢酝ㄟ^(guò)在ORDER BY子句中使用NEWID函數(shù)來(lái)對(duì)結(jié)果進(jìn)行排序的方法來(lái)實(shí)現(xiàn),代碼如下:  

  SELECT *

  FROM Northwind..Orders

  ORDER BY NEWID()

  SELECT TOP 10 *

  FROM Northwind..Orders

  ORDER BY NEWID()

相關(guān)頻道: eNews

您對(duì)本文或本站有任何意見(jiàn),請(qǐng)?jiān)谙路教峤?,謝謝!

投稿信箱:tougao@enet16.com