使用如下语句查询HZZXJSZLX表中HTH不在nc_is_collect表中的记录。HZZXJSZLX中有10多W条记录,而nc_is_collect表也有将近10W条记录。HZZXJSZLX 中HTH字段已经做过索引,nc_is_collect中FARMER_CD字段做过索引,但该SQL语句查询了将近20分钟还没出结果。请教对SQL语句的优化,提高查询速度。select * from hzzxjszlx where nd='2013'and htzt='2'and zfzt<>'2'and data_state='0' and hth not in (select farmer_cd from nc_is_collect where data_state='0'and nd='2013'
and audit_state='1'and is_collect='1' ) order by hth
and audit_state='1'and is_collect='1' ) order by hth
解决方案 »
- 求个懂报表的大吓帮助我下!我新来的
- 如何实现ORACLE的全库数据的检索啊,请大家多给点建议,非常感谢啊!!
- Hibernate保存Blob到Oracle中使用flush()时出错
- linux 下oracle数据库, 不能正确显示windows下插入的中文数据 ?
- 能否用java类的某一个方法生成oracle视图?
- 定义数据类型时varchar(20 char)和varchar(20)有什么区别?
- 有关Oracle中英文字符大小写的问题
- 安装oracle9i的问题
- 用proc这样可以查询并删除多条记录吗?
- C# 取oracle返回的多个结果集的问题
- 请教 分类 group by
- ORACLE解析XML报错
and audit_state='1'and is_collect='1') b where a.hth=b.farmer_cd(+) and b.farmer_cd is null求给分
where nd='2013'
and htzt='2'
and zfzt<>'2'
and data_state='0'
and not exists(select * from nc_is_collect
where data_state='0'
and nd='2013'
and audit_state='1'
and is_collect='1'
and hzzxjszlx.hth=nc_is_collect.farmer_cd);
from
hzzxjszlx a
left join
(select farmer_cd from nc_is_collect where data_state='0' and nd='2013' and audit_state='1' and is_collect='1' ) b
on a.hth=b.farmer_cd
where b.farmer_cd is null and nd='2013' and htzt='2'and (zfzt>'2' or zfzt<'2') and data_state='0'
order by hth;表关联最好用join,where条件中不要用<>,另外可以考虑修改一下表的字段类型