求一个高效的sql
现在有两张表,t1(a,b)t2(a,c,d,e,f,g,h,i) t2.a是t1.a的外键
要按t1的数据统计t2的c,d,e的重复列,f,g,h,i的为空列
t1有五百多数据,t2是上千万条数据,如果用按每个字段统计的话开发机器上跑一遍需要大一个小时时间,又没有什么方法可以提高一下查询效率
[解决办法]
参考 这个。。。。
Select a.Rowid
From emp a,
(Select Max(b.Rowid) Rowid1
From emp b
Group By b.empno,
b.ename,
b.job,
b.mgr,
b.hiredate,
b.sal,
b.comm,
b.deptno) Bb
Where a.Rowid = Bb.Rowid1(+)
And Bb.Rowid1 Is Null
[解决办法]
可以上语句 语句上面没优化 那就要考虑其他方面了
--索引建立
create index index_t2_a on t2(a,c,d,e);
[解决办法]
select t2a.a,t2a.c,t2a.d,t2a.e,t2a.f,t2a.g,t2a.h,t2a.i
from t2 t2a,t2 t2bt2a.d
where t2a.a = t2b.a and t2a.c=t2b.c and t2a.d=t2b.d and t2a.e=t2b.e
and t2a.f is null and t2a.g is null and t2a.h is null and t2a.i is null
group by t2a.a,t2a.c,t2a.d,t2a.e
不知道会不会快一些,你试试,只要不会更慢就算帮忙了,呵呵。
