22,209
社区成员
发帖
与我相关
我的任务
分享
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
)