zoukankan      html  css  js  c++  java
  • Oracle_in_not-in_distinct_minsu的用法

    create table a(
       id int,
       username varchar2(20)
    );
    
    
    create table b(
       id int,
       username varchar2(20)
    );
    
    insert into a  values(1,'小明');
    insert into a  values(2,'小红');
    insert into a  values(3,'小君');
    commit
    
    select * from a
    select * from b
    delete from a where id>=4
    
    insert into b  values(2,'小红');
    insert into b  values(4,'小星');
    insert into b  values(5,'小刘');
    去重 (查人数)
    select * from a
    union
    select * from b
    去重另一种写法
    select distinct * from (
      select * from a
      union all
      select * from b
    )
    不去重(速度快)
    select * from a
    union all
    select * from b

    求红色区域

    
    
    先查id

    select id from a where a.id in (select b.id from b)
    再查是谁 
    select * from a where id in(
        select id from b where b.id in (select a.id from a)
    )
    另一种方法
    select * from b where b.id in (select a.id from a)
    还有一种方法
    select b.* from a,b where a.id = b.id

     求红色区域

    select * from a where id not in (select id from b)

     not in 在oracle大数据时,速度非常慢,不建议使用

    select * from a where id in (
    
        select id from a
        minus
        select id from b
    
    )
  • 相关阅读:
    设计模式——设计模式之禅day2
    和阿文一起学H5——音乐素材
    mysql数据库问题
    vue-cli脚手架工具
    webpack总结
    sql和nosql区别
    MongoDB基本命令
    >nbsp修改
    字典
    列表
  • 原文地址:https://www.cnblogs.com/yncx/p/6432395.html
Copyright © 2011-2022 走看看