首页 新闻 会员 周边

数据库的优化急急急急急急急急急急急急

0
悬赏园豆:10 [已解决问题] 解决于 2012-11-22 11:08

select * from  Gallery.Galleries where Gallery.Galleries.CreatorId in
(select Gallery.Galleries.CreatorId from  Gallery.Galleries  group by Gallery.Galleries.CreatorId having COUNT(Gallery.Galleries.CreatorId)>1 ) Order by CreatorId


select * from Gallery.Galleries where exists (select Gallery.Galleries.CreatorId from  Gallery.Galleries  group by Gallery.Galleries.CreatorId having COUNT(Gallery.Galleries.CreatorId)>1)Order by CreatorId

今天进行数据库的优化,本来以为in可以更改为exists可以提高性能但是更改过后查出来的内容不一样,求原因。

MingHao_Hu的主页 MingHao_Hu | 初学一级 | 园豆:8
提问于:2012-11-22 10:26
< >
分享
最佳答案
0

第二个语句exists里面 只要有一个creatorid有多行,就会一直有值,所以第二个应该是全都查出来了。

收获园豆:10
飞来飞去 | 老鸟四级 |园豆:2057 | 2012-11-22 10:55
select * from Gallery.Galleries as a
where (select count(1) from Gallery.Galleries as b where b.CreatorId=a.CreatorId)>1
order by CreatorId
飞来飞去 | 园豆:2057 (老鸟四级) | 2012-11-22 10:56

@飞来飞去: 不好意思我刚刚看了下查询计划,好像两个差不多。。。

飞来飞去 | 园豆:2057 (老鸟四级) | 2012-11-22 10:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册