Hive supports the following types of traditional relational database syntax:
Syntax description:
For example, the table_test table exists in Hive and the table structure is as follows:
+----------------+-------------------+--+ | table_test.id | table_test.value | +----------------+-------------------+--+ | 1 | 10 | | 1 | 15 | | 2 | 20 | | 2 | 5 | | 2 | 13 | +----------------+-------------------+--+
Run the following statement:
select id,grouping(id),sum(value) from table_test group by id with rollup;
The result is as follows:
+-------+-----------------+------+--+ | id | groupingresult | sum | +-------+-----------------+------+--+ | 1 | 0 | 25 | | NULL | 1 | 63 | | 2 | 0 | 38 | +-------+-----------------+------+--+
Syntax description:
For example, two tables test_table1 and test_table2 exist in Hive.
The table structure of test_table1 is as follows:
+-----------------+--+ | test_table1.id | +-----------------+--+ | 1 | | 2 | | 3 | | 4 | +-----------------+--+
The table structure of test_table2 is as follows:
+-----------------+--+ | test_table2.id | +-----------------+--+ | 2 | | 3 | | 4 | | 5 | +-----------------+--+
select id from test_table1 except select id from test_table2;
The result is as follows:
+--------------+--+ | _alias_0.id | +--------------+--+ | 1 | +--------------+--+
select id from test_table1 intersect select id from test_table2;
The result is as follows:
+--------------+--+ | _alias_0.id | +--------------+--+ | 2 | | 3 | | 4 | +--------------+--+