zoukankan      html  css  js  c++  java
  • 不同数据库取并集、交集、差集

    一、mysql取并交差集

    1)mysql取并集

    用union/union all关键字

    2)mysql取交集:

    需求:选出既在t1表又在t2表的数据,t1、t2两表字段都只有age和name

    mysql数据库取交集没有对应的关键字,可以用内连接,如下

    select t1.* from t1

    inner join t2 on t1.age = t2.age and t1.name = t2.name;

    3)mysql取差集:

    需求:选出在t1表中但不在t2表中的数据

    mysql数据库取差集也没有对应的关键字,可以用外连接,如下:

    select t1.* from t1

    left join t2 on t1.age = t2.age and t1.name = t2.name

    where t2.age is null;

    mysql数据库取差集也可以用not exists,如下

    select * from t1 

    where not exists (select 1 from t2 where t1.age = t2.age and t1.name = t2.name);

     

    二、postgresql取并交差集

    postgresql取并集,可以用union/union all关键字;取交集,可以用intersect关键字;取差集,可以用except关键字。

    三、oracle取并交差集

    oracle取并集,可以用union/union all关键字;取交集,可以用intersect关键字;取差集,可以用minus关键字。

  • 相关阅读:
    Oracle And子句
    Oracle Where(条件)子句用法
    extern “C”的作用详解
    函数重载
    给变量起名字的网站。
    同步异步
    CCS5.5安装破解过程
    Semaphore_pend();阻塞函数
    vi常用命令
    Linux下VI操作命令
  • 原文地址:https://www.cnblogs.com/koushr/p/5873430.html
Copyright © 2011-2022 走看看