zoukankan      html  css  js  c++  java
  • Flink基础(129):FLINK-SQL语法 (23) DQL(15) OPERATIONS(12)Set Operations 集合操作

    1 UNION 

    UNION and UNION ALL return the rows that are found in either table. UNION takes only distinct rows while UNION ALL does not remove duplicates from the result rows.

    Flink SQL> create view t1(s) as values ('c'), ('a'), ('b'), ('b'), ('c');
    Flink SQL> create view t2(s) as values ('d'), ('e'), ('a'), ('b'), ('b');
    
    Flink SQL> (SELECT s FROM t1) UNION (SELECT s FROM t2);
    +---+
    |  s|
    +---+
    |  c|
    |  a|
    |  b|
    |  d|
    |  e|
    +---+
    
    Flink SQL> (SELECT s FROM t1) UNION ALL (SELECT s FROM t2);
    +---+
    |  c|
    +---+
    |  c|
    |  a|
    |  b|
    |  b|
    |  c|
    |  d|
    |  e|
    |  a|
    |  b|
    |  b|
    +---+

    2 INTERSECT 

    INTERSECT and INTERSECT ALL return the rows that are found in both tables. INTERSECT takes only distinct rows while INTERSECT ALL does not remove duplicates from the result rows.

    Flink SQL> (SELECT s FROM t1) INTERSECT (SELECT s FROM t2);
    +---+
    |  s|
    +---+
    |  a|
    |  b|
    +---+
    
    Flink SQL> (SELECT s FROM t1) INTERSECT ALL (SELECT s FROM t2);
    +---+
    |  s|
    +---+
    |  a|
    |  b|
    |  b|
    +---+

    3 EXCEPT 

    EXCEPT and EXCEPT ALL return the rows that are found in one table but not the other. EXCEPT takes only distinct rows while EXCEPT ALL does not remove duplicates from the result rows.

    Flink SQL> (SELECT s FROM t1) EXCEPT (SELECT s FROM t2);
    +---+
    | s |
    +---+
    | c |
    +---+
    
    Flink SQL> (SELECT s FROM t1) EXCEPT ALL (SELECT s FROM t2);
    +---+
    | s |
    +---+
    | c |
    | c |
    +---+

    4 IN

    Returns true if an expression exists in a given table sub-query. The sub-query table must consist of one column. This column must have the same data type as the expression.

    SELECT user, amount
    FROM Orders
    WHERE product IN (
        SELECT product FROM NewProducts
    )

    The optimizer rewrites the IN condition into a join and group operation. For streaming queries, the required state for computing the query result might grow infinitely depending on the number of distinct input rows. You can provide a query configuration with an appropriate state time-to-live (TTL) to prevent excessive state size. Note that this might affect the correctness of the query result. See query configuration for details.

    5 EXISTS

    SELECT user, amount
    FROM Orders
    WHERE product EXISTS (
        SELECT product FROM NewProducts
    )

    Returns true if the sub-query returns at least one row. Only supported if the operation can be rewritten in a join and group operation.

    The optimizer rewrites the EXISTS operation into a join and group operation. For streaming queries, the required state for computing the query result might grow infinitely depending on the number of distinct input rows. You can provide a query configuration with an appropriate state time-to-live (TTL) to prevent excessive state size. Note that this might affect the correctness of the query result. See query configuration for details.

    本文来自博客园,作者:秋华,转载请注明原文链接:https://www.cnblogs.com/qiu-hua/p/15195920.html

  • 相关阅读:
    PHP防采集方法代码
    Borland C++ Builder 编译绿色Exe程序
    关于结构体构造函数使用总结
    Ubuntu18下移植飞凌的QT4.8.5
    qt在arm平台中,把鼠标指针消失。
    ubuntu下gcc g++操作
    Ubuntu下Qt_Creator支持搜狗中文输入
    ubuntu18.04.1降级交叉编译器 arm-linux-gcc-4.4.3
    error: narrowing conversion of '4323168000' from 'long int' to 'float' inside { } [-Wnarrowing] }; ^
    #pragma pack(1)的意义
  • 原文地址:https://www.cnblogs.com/qiu-hua/p/15195920.html
Copyright © 2011-2022 走看看