oracle集合运算

 

 oracle集合运算
一 介绍
 1.集合运算符包括并集(union/union all),交集(intersect),差集(minus).
 2.并集:union运算符返回两个集合去掉重复元素后的所有记录。
                union返回集合的所有元素,包括重复的元素
3.交集:intersect运算符返回同时属于两个集合的记录
4.差集:minus返回属于第一个集合,但是不属于第二个集合的记录
二  举例:
1.union 并集  举例:
SQL> select * from emp where deptno=10
  2  union
  3  select * from emp where deptno=20;

或写为:SQL> select * from  emp  where deptno in(10,20);
也就是合并,取消两集重复的元素

SQL> select * from emp where ename like '%A%'
  2  union
  3  select * from  emp where ename like '%M%';


SQL> select * from emp where ename like '%A%' or ename like '%M%';


2.union all  并集
SQL> select * from emp where deptno=10
2  union all
3  select * from emp where deptno=20;


 3.intersect 交集
例1
SQL> select * from emp where ename like '%A%'
  intersect
  select * from emp where ename like '%M%';

例2
SQL> select * from emp where sal between 700 and 1300
 intersect
select * from emp where sal between 1200 and 1400;

4. minus 差集
SQL>select * from emp where sal between 700 and 1300
 minus
 select * from emp where sal between 1200 and 1400

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值