zoukankan      html  css  js  c++  java
  • SQL联合查询

    集合运算  http://www.cnblogs.com/geminichao/p/5672919.html

    基合运算符可以用于从多张表中选择数据。

    ①UNION运算
    用于求两个结果集合的并集(两个结果集合的所有记录),并自动去掉重复行。

    select ename,sal from account where sal>2000
    union
    select ename,sal from research where sal>2000
    union
    select ename,sal from sales where sal>2000;

    注:ename,sal 是必须一致的。 
    ②UNION ALL运算
    用于求两个结果集合的并集(两个结果集中的所有记录),并且不去掉重复行。

    select ename,sal from account where sal>2000
    union
    select ename,sal from research where sal>2000
    union
    select ename,sal from sales where sal>2000;

    ③INTERSECT运算
    intersect运算返回查询结果中相同的部分。
    各部门中有哪些相同的职位?

    select Job from account
    intersect
    select Job from research
    intersect
    select Job from sales;

    ④MINUS运算
    minus返回两个结果集的差集。(在第一个结果集中存在的,而在第二个结果集中不存在的行。)

    有那些职位是财务部中有,而在销售部门中没有?

    select Job from account
    minus
    select Job from sales;

    其他补充:

    http://www.cnblogs.com/yank/p/3758107.html

  • 相关阅读:
    二进制位运算
    Leetcode 373. Find K Pairs with Smallest Sums
    priority_queue的用法
    Leetcode 110. Balanced Binary Tree
    Leetcode 104. Maximum Depth of Binary Tree
    Leetcode 111. Minimum Depth of Binary Tree
    Leetcode 64. Minimum Path Sum
    Leetcode 63. Unique Paths II
    经典的递归练习
    案例:java中的基本排序
  • 原文地址:https://www.cnblogs.com/lansan0701/p/SQL.html
Copyright © 2011-2022 走看看