SQLBUG集之"随机排序中的newid()问题"

来源:互联网 发布:工资管理系统数据库 编辑:程序博客网 时间:2024/04/29 17:24
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

/**==**2.随机排序中newid()问题**==**/--测试数据declare@ttable(namechar(1),valueint)insertinto@tselect'a',1unionallselect'a',2unionallselect'b',3unionallselect'b',4unionallselect'c',5unionallselect'c',6

--要求,随机排序,但name相同的要排在一齐selecta.*from@tajoin( selectaa=newid(),namefrom(selectdistinctnamefrom@t)a)bona.name=b.nameorderbyb.aa,newid()

/*--测试结果之一,并没有达到要求.如果将join改成leftrightfulljoin,就正确namevalue      ---------------b   4b   3c   5a   1a   2c   6

(所影响的行数为6行)--*/

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击