UNION ALL语句将两个流式数据合并。要求两个流式数据的字段完全一致,包括字段类型和字段顺序。

语法

select_statement
UNION ALL
select_statement;
说明 实时计算同样支持UNION函数。UNION ALL允许重复值,UNION不允许重复值。在实时计算底层,UNIONUNION ALL + Distinct ,运行效率较低,一般不推荐使用UNION

示例

  • 测试数据

    test_source_union1

    a(varchar) b(bigint) c(bigint)
    test1 1 10

    test_source_union2

    a(varchar) b(bigint) c(bigint)
    test1 1 10
    test2 2 20

    test_source_union3

    a(varchar) b(bigint) c(bigint)
    test1 1 10
    test2 2 20
    test1 1 10
  • 测试语句
    SELECT
        a,
        sum(b),
        sum(c)
    FROM 
        (SELECT * from test_source_union1
        UNION ALL
        SELECT * from test_source_union2
        UNION ALL
        SELECT * from test_source_union3
        )t
     GROUP BY a;      
  • 测试结果
    d(varchar) e(bigint) f(bigint)
    test1 1 10
    test2 2 20
    test1 2 20
    test1 3 30
    test2 4 40
    test1 4 40