UNION ALL ステートメントは、2 つのデータストリームを組み合わせて使用されます。 2 つのデータストリームのフィールドは、フィールドタイプと順序が同じである必要があります。
構文
select_statement
UNION ALL
select_statement;
注 Realtime Compute は
UNION
関数もサポートします。 UNION ALL
は、重複した値を取ることができるのに対し、UNION
では対応していません。 Realtime Compute の下位層では、UNION
は、UNION 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