/**==** 2. 隨機排序中的newid()問題 **==**/--測試數據declare @t table(name char(1),value int)insert into @tselect 'a',1union all select 'a',2union all select 'b',3union all select 'b',4union all select 'c',5union all select 'c',6
--要求,隨機排序,但name相同的要排在一齊select a.*from @t a join( select aa=newid(),name from(select distinct name from @t) a) b on a.name=b.nameorder by b.aa,newid()
/*--測試結果之一,并沒有達到要求.如果將join改成left right full join,就正確name value ---- ----------- b 4b 3c 5a 1a 2c 6
(所影響的行數為 6 行)--*/