zoukankan      html  css  js  c++  java
  • [学习笔记] Oracle集合运算、内连接、外连接、伪列

    集合运算

    • INTERSECT(交集),返回两个查询共有的记录。

    • UNION ALL(并集重复),返回各个查询的所有记录,包括重复记录。

    • UNION(并集不重复),返回各个查询的所有记录,不包括重复记录 。

    • MINUS(补集),返回第一个查询的记录减去第二个查询的记录之后剩余的记录。

    -- 交集
    select * from stuinfo1 
    intersect
    select * from stuinfo2;
    
    -- 并集重复
    select * from stuinfo1 
    union all
    select * from stuinfo2;
    
    -- 并集不重复
    select * from stuinfo1 
    union 
    select * from stuinfo2;
    
    -- 补集
    select * from stuinfo1 
    minus
    select * from stuinfo2;
    

    内连接

    两张表通过某个字段进行内关联,查询结果是通过该字段按关系运算符匹配出的数据行。

    select a.stuid, a.stuname, a.classno,
           b.classno, b.classname, b.monitorid, b.monitorname
    from stuinfo a, class b
    where a.classno = b.classno;
    

    外连接

    • left join:等价于 left outer join,返回左表中的所有记录和右表中联结字段相等的记录。

    • right join:等价于 right outer join,返回右表中的所有记录和左表中联结字段相等的记录。

    • full join:等价于 full outer join,查询结果等于左外连接和右外连接的和。

    --左外连接(stuinfo1表中数据都保留,stuinfo2不在stuinfo1中存在的字段为null值)
    select a.*, b.stuid, b.stuname
    from stuinfo1 a left join stuinfo2 b
    on a.stuid = b.stuid;
    
    --左外连接另外一种写法
    select a.*, b.stuid, b.stuname
    from stuinfo1 a,stuinfo2 b 
    where a.stuid = b.stuid(+);
    
    --右外连接(stuinfo2表中数据都保留,stuinfo1不在stuinfo2中存在的字段为null值)
    select a.*, b.stuid, b.stuname
    from stuinfo1 a right join stuinfo2 b
    on a.stuid = b.stuid;
    
    --右外连接另外一种写法
    select a.*, b.stuid, b.stuname
    from stuinfo1 a,stuinfo2 b 
    where a.stuid(+)=b.stuid;
    
    --全外连接(stuinfo1、stuinfo2表中数据都保留,stuinfo1不在stuinfo2存在的学生相关字段为null值,stuinfo2不在stuinfo1存在的学生相关字段为null值)
    select a.*, b.stuid, b.stuname
    from stuinfo1 a full join stuinfo2 b
    on a.stuid = b.stuid;
    

    伪列

    • ROWID:返回数据在数据文件中的物理地址。ROWID 值可以唯一的标识表中的一行。
    • ROWNUM:标识查询结果集的顺序,第一行标识为1,后面依次递增。
    select t.*, t.rowid from stuinfo t;
    select t.*, t.rowid from stuinfo t where t.rowid='AAAShjAAEAAAAEFAAD';
    
    select t.*, rownum from stuinfo t;
    
    -- 返回学生信息表中学生年龄最低的前四位同学
    select * from (
    	select t.*, rownum from stuinfo t order by t.age asc
    ) where rownum <= 4;
    
  • 相关阅读:
    还在使用golang 的map 做Json编码么?
    Golang 性能测试(2) 性能分析
    golang 性能测试 (1) 基准性能测试
    消息队列 NSQ 源码学习笔记 (五)
    消息队列 NSQ 源码学习笔记 (四)
    消息队列 NSQ 源码学习笔记 (三)
    消息队列 NSQ 源码学习笔记 (二)
    消息队列 NSQ 源码学习笔记 (一)
    你不知道的空格
    Supervisor 使用和进阶4 (Event 的使用)
  • 原文地址:https://www.cnblogs.com/danhuang/p/12497155.html
Copyright © 2011-2022 走看看