MAPREDUCE服务 MRS-Hive支持的传统关系型数据库语法说明:EXCEPT、INTERSECT

时间:2024-08-01 19:24:44

EXCEPT、INTERSECT

  • EXCEPT返回两个结果集的差(即从左查询中返回右查询没有找到的所有非重复值)。
  • INTERSECT返回两个结果集的交集(即两个查询都返回的所有非重复值)。

例如,Hive中有两张表“test_table1”“test_table2”

“test_table1”表结构如下所示:

+-----------------+--+
| test_table1.id  |
+-----------------+--+
| 1               |
| 2               |
| 3               |
| 4               |
+-----------------+--+

“test_table2”表结构如下所示:

+-----------------+--+
| test_table2.id  |
+-----------------+--+
| 2               |
| 3               |
| 4               |
| 5               |
+-----------------+--+
  • 执行如下的EXCEPT语句:

    select id from test_table1 except select id from test_table2;

    显示如下结果:

    +--------------+--+
    | _alias_0.id  |
    +--------------+--+
    | 1            |
    +--------------+--+
  • 执行INTERSECT语句:

    select id from test_table1 intersect select id from test_table2;

    显示如下结果:

    +--------------+--+
    | _alias_0.id  |
    +--------------+--+
    | 2            |
    | 3            |
    | 4            |
    +--------------+--+
support.huaweicloud.com/cmpntguide-lts-mrs/mrs_01_0962.html