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关键字。

  • 相关阅读:
    2019省赛训练组队赛4.9周二 2017浙江省赛
    #Leetcode# 49. Group Anagrams
    #Leetcode# 57. Insert Interval
    POJ 2195 Going Home
    HDU 2255 奔小康赚大钱
    HDU 1083 Courses
    HDU 2063 过山车
    POJ 3041 Asteroids
    指针的妙处
    jzoj 6273. 2019.8.4【NOIP提高组A】欠钱 (money)
  • 原文地址:https://www.cnblogs.com/koushr/p/5873430.html
Copyright © 2011-2022 走看看