not in 优化方法?

lula 2008-06-11 07:37:38
select * from emp where emp_no not in (select emp_no from emp_bill)

要求用两种SQL写法优化上面SQL,谢谢
...全文
2028 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
anerou 2010-01-13
  • 打赏
  • 举报
回复
收藏先
luyanvv 2009-10-09
  • 打赏
  • 举报
回复
今天天气不错,适合出来逛CSDN,~~~~~路过
changweishao 2008-06-14
  • 打赏
  • 举报
回复
解决方案挺多的,人齐,可以结贴
yugas 2008-06-14
  • 打赏
  • 举报
回复
执行一下疾患看看结果是否是一样...我感觉最主要是看计划...
DragonBill 2008-06-14
  • 打赏
  • 举报
回复
4楼的写得不错,大致补充几点:

1,

select a.* 
from emp a ,emp_bill b
where a.emp_no=b.emp_no(+)
and b.emp_no is null

改为
select a.* 
from emp a ,emp_bill b
where a.emp_no=b.emp_no(+)
and NVL(b.emp_no, '1') = '1'

要好一些


2, 如果DB是10g, 可考虑用LNNVL function, 如下:

SELECT A.* FROM EMP A, EMP_BILL B WHERE LNNVL(A.EMP_NO = B.EMP_NO);
sulins 2008-06-14
  • 打赏
  • 举报
回复
4楼正解。
samuellei 2008-06-13
  • 打赏
  • 举报
回复
1.
select a.*
from emp a, emp_no b
where a.emp_no != b.emp_no

2.
select *
from emp
where emp.emp_no in (select emp_no from emp minus select emp_no from emp_bll)
qixiao 2008-06-13
  • 打赏
  • 举报
回复
表连接效率最好,Not Exists其次,Not in最低
dencyzhang 2008-06-13
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 hebo2005 的回复:]
方法一 还有点错误



SQL codeselect *
from emp a
where not exists (select 1
from emp_bill b
where b.emp_no=a.emp_no)




方法2

SQL codeselect a.*
from emp a ,emp_bill b
where a.emp_no=b.emp_no(+)
and b.emp_no is null
[/Quote]

支持以上2种方法
huoxudong125 2008-06-13
  • 打赏
  • 举报
回复
这种情况一般用not exits处理。

snowy_howe 2008-06-12
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 LJY_AINILU 的回复:]
引用 5 楼 qiyousyc 的回复:
这种情况一般用exits处理。
select * from emp a where
not exists (select 1from emp_bill b where b.emp.no=a.emp_no)



select 1 有什么用啊 是什么意思
[/Quote]

select 1 是一种用法,也可以select 某字段
或者select 'x'都行的,也就是说exists其实
是判断是否有数据返回,而不关心返回的数据。
LJY_AINILU 2008-06-12
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 qiyousyc 的回复:]
这种情况一般用exits处理。
select * from emp a where
not exists (select 1from emp_bill b where b.emp.no=a.emp_no)


[/Quote]
select 1 有什么用啊 是什么意思
hhfwyl 2008-06-12
  • 打赏
  • 举报
回复
欢迎加入oracle qq群9701750
chensi05 2008-06-12
  • 打赏
  • 举报
回复
SELECT *
FROM EMP A
WHERE NOT EXISTS (SELECT 1 FROM EMP_BILL B WHERE B.EMP_NO = A.EMP_NO)
CathySun118 2008-06-12
  • 打赏
  • 举报
回复
select a.* from emp a,emp_bill b where a.emp_no <>b.emp_no
select * from emp a where emp_no not exists (select emp_no b from emp_bill where a.emp_no <>b.emp_no)
hebo2005 2008-06-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 arsenal1999 的回复:]
select *
from emp
where emp_no in(select emp_no from emp minus select emp_no from emp_bill );

select a.*
from emp a,(select emp_no from emp minus select emp_no from emp_bill ) b
where a.emp_no = b.emp_no;

可以么?


[/Quote]
你这效率不行的,要做三次访问表,去看下执行计划就知道了
qiyousyc 2008-06-11
  • 打赏
  • 举报
回复
这种情况一般用exits处理。
select * from emp a where
not exists (select 1from emp_bill b where b.emp.no=a.emp_no)

hebo2005 2008-06-11
  • 打赏
  • 举报
回复
方法一 还有点错误


select * 
from emp a
where not exists (select 1
from emp_bill b
where b.emp_no=a.emp_no)




方法2
select a.* 
from emp a ,emp_bill b
where a.emp_no=b.emp_no(+)
and b.emp_no is null
hebo2005 2008-06-11
  • 打赏
  • 举报
回复
方法一

select *
from emp a
where not exists (select 1
from emp_bill b
where b.emp.no=a.emp_no)
hebo2005 2008-06-11
  • 打赏
  • 举报
回复
select * 
from emp a
where no exists (select 1
from emp_bill b
where b.emp.no=a.emp_no)
加载更多回复(1)
每天前100人再送5门编程课! AI+5门300元课程+社群闭门分享会源码开源下载:https://github.com/DjangoPeng/keras-101/tree/master/code_samples 【为什么学AI】 归功于近年来大规模数据和硬件计算能力的大幅度提升,人工智能的概念近两年一直是市场追捧的对象。目前各大厂都争先恐后地布局AI,落地各类AI的的商业应用,也随之打响了一场激烈的人才争夺战。长远来看,越快将 AI 用于自己的工作中就能越早体会到AI带来的收益。 【讲师介绍】 彭靖田 Google Developer Experts。 曾为 TensorFlow Top级 的贡献者,著书《深入理解TensorFlow》,是国内第一本深度剖析 Google AI 框架的畅销书。 曾从0到1深入参与了华为 2012 实验室深度学习平台和华为深度学习云服务的设计与研发工作。 【课程设计】 课程内容基于最新的Keras版本(你也可以使用 TensorFlow 2 的 tf.keras 模块),其中有大量独家解读、案例,以及不少讲师一线实战多年的方法论和深度思考。同时,在层次划分上,难易兼顾,循序渐进。既有核心的基础知识,也有高级的进阶操作,尽量做到“老少皆宜”。 课程分为基础篇、入门篇和实战篇: 一、基础篇: 主要讲解人工智能发展史和深度学习脱颖而出的原由,以及神经网络的基础概念、理论实现、优化原理和计算方法。 二、入门篇: 主攻快速上手,通过7个小节让你从0到1实现环境搭建、模型优化,直接试水2个实战项目。同时,增强AI的理论学习,系统掌握机器学习3大分支、模型评估方法、数据预处理常用手段与过拟合问题的解决方案。 三、实战篇: 通过4个实战全面掌握深度学习理论与实现,涵盖目标检测、图像分类、可视化和可解释性学习、迁移学习、特征提取、数据增强等。带你综合运用前面所学的所有知识,逐渐熟练AI开发流程与技能。 课程包含思维导图上的所有内容(价值199元)前500名立减100元,仅99元买完就能学!

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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