/**==** 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 行)--*/