[摘要]/**==** 2. 随机排序中的newid()问题 **==**/ --测试数据 declare @t table(name char(1),value int) insert into @t s...
/**==** 2. 随机排序中的newid()问题 **==**/ 
--测试数据 
declare @t table(name char(1),value int) 
insert into @t 
select ’a’,1 
union all select ’a’,2 
union all select ’b’,3 
union all select ’b’,4 
union all select ’c’,5 
union 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.name 
order by b.aa,newid() 
/*--测试结果之一,并没有达到要求.如果将join改成left right full join,就正确 
name value        
---- -----------  
b    4 
b    3 
c    5 
a    1 
a    2 
c    6 
(所影响的行数为 6 行) 
--*/
全新的路由器不仅让你更稳定快速地连接无线网络,更可以让家中的智能设备连接在一起。
  关键词:随机排序中的newid()问题