关于执行效率的问题
测试表a b
大家谈谈下列两种方式,哪种的执行效率要高些
--1.
select a.c1,a.c2,sum(a.c3) as c3,sum(b.cc) as cc
from a
join b
on a.c1=b.c1 and a.c2=b.c2
where a.c1 <> 1 and b.c2 <> 5
group by a.c1,a.c2
--2.
select x.c1,x.c2,x.c3,y.cc
from (select c1,c2,sum(c3) as c3 from a where a.c1 <> 1 group by c1,c2)as x
join (select c1,c2,sum(cc) as cc from b where b.c1 <> 1 group by c1,c2)as y
on a.c1=b.c1 and a.c2=b.c2
------解决方案--------------------用方法1
------解决方案--------------------建議使用方法一
------解决方案--------------------方法一的效率高,因为在方法二中运用连接的同时又创建了两个衍生表x和y.