欢迎光临
我们一直在努力

SQL BUG集之"随机排序中的newid()问题"-数据库专栏,SQL Server

建站超值云服务器,限时71元/月

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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » SQL BUG集之"随机排序中的newid()问题"-数据库专栏,SQL Server
分享到: 更多 (0)