呵呵,牛皮一下,满足一下自己的虚荣心:这就是效率!

luoyoumou 2009-10-29 01:49:43
---欢迎大家去测试:
---原帖地址:
http://topic.csdn.net/u/20091029/11/94d112b0-601c-4e30-91f6-7b215393fe0f.html?61819
drop table a;

--------楼主:可以去测试一下:什么是效率!
create table a(dwdm int, dm varchar(4));

----循环插入8000000条记录行
declare @a int
set @a=1000000;
while(@a>0)
begin
insert into a(dwdm, dm)
select
1,'5' union all select
1,'-' union all select
2,'-' union all select
2,'-' union all select
3,'-' union all select
3,'s' union all select
3,'-' union all select
4,'-';
set @a=@a-1
end;

--------8秒钟出数据
select dwdm
from a
group by dwdm
having count(dwdm)=sum(case dm when '-' then 1 else 0 end);

--------10分钟了,还没出数据
select distinct DWDM from a t
where not exists (
select 1 from a where DWDM = t.DWDM and DM <> t.DM
)
...全文
435 63 打赏 收藏 转发到动态 举报
写回复
用AI写文章
63 条回复
切换为时间正序
请发表友善的回复…
发表回复
pbsh 2009-10-30
  • 打赏
  • 举报
回复
人齐了,可以结帖了。
Flyingdragon168 2009-10-30
  • 打赏
  • 举报
回复
學習一下了。
Four 2009-10-30
  • 打赏
  • 举报
回复
study
  • 打赏
  • 举报
回复
说一下原理,我想学一下
yuzhifu1 2009-10-30
  • 打赏
  • 举报
回复
jf
jack_ailly 2009-10-29
  • 打赏
  • 举报
回复
不错,学习
viva369 2009-10-29
  • 打赏
  • 举报
回复
留名
ok1411 2009-10-29
  • 打赏
  • 举报
回复
学习下
Yang_ 2009-10-29
  • 打赏
  • 举报
回复
[Quote=引用 48 楼 luoyoumou 的回复:]
引用 44 楼 yang_ 的回复:
这两个语句没有可比性,意思不一样

--------8秒钟出数据(dm全部='-'的wdm)
select dwdm
from a
group by dwdm
having count(dwdm)=sum(case dm when '-' then 1 else 0 end);

--------10分钟了,还没出数据(DM只有一个值的DWDM)
select distinct DWDM from a t
where not exists (
    select 1 from a where DWDM = t.DWDM and DM <> t.DM
)




---呵呵:有道理,看来让我白高兴了一场,其实创建索引,用exists语句,其效率还是挺高的!
[/Quote]
刚才忙去了

和你的语句对应的应该是

select distinct DWDM from a t
where not exists (
select 1 from a where DWDM = t.DWDM and DM <> '-'
)

效率和你的差不多

华夏小卒 2009-10-29
  • 打赏
  • 举报
回复
接分
luoyoumou 2009-10-29
  • 打赏
  • 举报
回复
[Quote=引用 51 楼 guguda2008 的回复:]
引用 49 楼 feixianxxx 的回复:
而且这800w数据毫无价值 ..都一样的数值.... 分组还是这么几组...

不过我测试了一下200W数据10W个分组,结果差不多啊,还是5S和1S
[/Quote]

----呵呵:还是鸭子厉害!不愧是“北京烤鸭”!
guguda2008 2009-10-29
  • 打赏
  • 举报
回复
[Quote=引用 49 楼 feixianxxx 的回复:]
而且这800w数据毫无价值 ..都一样的数值.... 分组还是这么几组...
[/Quote]
不过我测试了一下200W数据10W个分组,结果差不多啊,还是5S和1S
luoyoumou 2009-10-29
  • 打赏
  • 举报
回复
---哎..........100分打水泡了,虚荣心也被打击得..............
feixianxxx 2009-10-29
  • 打赏
  • 举报
回复
而且这800w数据毫无价值 ..都一样的数值.... 分组还是这么几组...
luoyoumou 2009-10-29
  • 打赏
  • 举报
回复
[Quote=引用 44 楼 yang_ 的回复:]
这两个语句没有可比性,意思不一样

--------8秒钟出数据(dm全部='-'的wdm)
select dwdm
from a
group by dwdm
having count(dwdm)=sum(case dm when '-' then 1 else 0 end);

--------10分钟了,还没出数据(DM只有一个值的DWDM)
select distinct DWDM from a t
where not exists (
    select 1 from a where DWDM = t.DWDM and DM <> t.DM
)


[/Quote]

---呵呵:有道理,看来让我白高兴了一场,其实创建索引,用exists语句,其效率还是挺高的!
feixianxxx 2009-10-29
  • 打赏
  • 举报
回复
...这个不是很明显么?。。。你数据量这么大
第二种方法 外表没测试一条就跑一次800w的表扫描》。。
nzperfect 2009-10-29
  • 打赏
  • 举报
回复
sql server 2000 ?
update sysdatabases set status=0 where name='数据库名称' 能不能执行?
sweetBug 2009-10-29
  • 打赏
  • 举报
回复
未看懂,标记先!
Yang_ 2009-10-29
  • 打赏
  • 举报
回复
这两个语句没有可比性,意思不一样

--------8秒钟出数据 (dm全部='-'的wdm)
select dwdm
from a
group by dwdm
having count(dwdm)=sum(case dm when '-' then 1 else 0 end);

--------10分钟了,还没出数据 (DM只有一个值的DWDM)
select distinct DWDM from a t
where not exists (
select 1 from a where DWDM = t.DWDM and DM <> t.DM
)

csdyyr 2009-10-29
  • 打赏
  • 举报
回复
学习。
加载更多回复(41)

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧