hive sql 中的运算_SQL中的SET运算

hive sql 中的运算

SQL supports few Set operations which can be performed on the table data. These are used to get meaningful results from data stored in the table, under different special conditions.

SQL支持很少的可以对表数据执行的Set操作。 这些用于在不同的特殊条件下从表中存储的数据中获取有意义的结果。

In this tutorial, we will cover 4 different types of SET operations, along with example:

在本教程中,我们将介绍4种不同类型的SET操作以及示例:

  1. UNION

    联盟

  2. UNION ALL

    全联盟

  3. INTERSECT

    相交

  4. MINUS

    减去

联盟行动 (UNION Operation)

UNION is used to combine the results of two or more SELECT statements. However it will eliminate duplicate rows from its resultset. In case of union, number of columns and datatype must be same in both the tables, on which UNION operation is being applied.

UNION用于合并两个或多个SELECT语句的结果。 但是,它将从结果集中消除重复的行。 如果使用并集,则在两个表上要应用UNION操作的列数和数据类型必须相同。

union set operation in sql
UNION示例 (Example of UNION)

The First table,

第一张桌子

IDName
1abhi
2adam
ID 名称
1个 阿比
2 亚当

The Second table,

第二张桌子

IDName
2adam
3Chester
ID 名称
2 亚当
3 切斯特

Union SQL query will be,

Union SQL查询将是,

SELECT * FROM First 
UNION
SELECT * FROM Second;

The resultset table will look like,

结果集表如下所示:

IDNAME
1abhi
2adam
3Chester
ID 名称
1个 阿比
2 亚当
3 切斯特

全联盟 (UNION ALL)

This operation is similar to Union. But it also shows the duplicate rows.

此操作类似于联合。 但它也显示重复的行。

union all set operation in sql
全部联合示例 (Example of Union All)

The First table,

第一张桌子

IDNAME
1abhi
2adam
ID 名称
1个 阿比
2 亚当

The Second table,

第二张桌子

IDNAME
2adam
3Chester
ID 名称
2 亚当
3 切斯特

Union All query will be like,

联合所有查询将是这样,

SELECT * FROM First 
UNION ALL
SELECT * FROM Second;

The resultset table will look like,

结果集表如下所示:

IDNAME
1abhi
2adam
2adam
3Chester
ID 名称
1个 阿比
2 亚当
2 亚当
3 切斯特

相交 (INTERSECT)

Intersect operation is used to combine two SELECT statements, but it only retuns the records which are common from both SELECT statements. In case of Intersect the number of columns and datatype must be same.

相交操作用于二者结合起来SELECT语句,但它只是retuns这是从两个共同记录SELECT语句。 在相交的情况下,列数和数据类型必须相同。

NOTE: MySQL does not support INTERSECT operator. 注意: MySQL不支持INTERSECT运算符。
intersect set operatoin in sql
相交的例子 (Example of Intersect)

The First table,

第一张桌子

IDNAME
1abhi
2adam
ID 名称
1个 阿比
2 亚当

The Second table,

第二张桌子

IDNAME
2adam
3Chester
ID 名称
2 亚当
3 切斯特

Intersect query will be,

相交查询将是

SELECT * FROM First 
INTERSECT
SELECT * FROM Second;

The resultset table will look like

结果集表如下所示

IDNAME
2adam
ID 名称
2 亚当

减去 (MINUS)

The Minus operation combines results of two SELECT statements and return only those in the final result, which belongs to the first set of the result.

减号运算组合两个SELECT语句的结果,并且仅返回最终结果(属于结果的第一组)中的结果。

minus set operation in sql
减号示例 (Example of Minus)

The First table,

第一张桌子

IDNAME
1abhi
2adam
ID 名称
1个 阿比
2 亚当

The Second table,

第二张桌子

IDNAME
2adam
3Chester
ID 名称
2 亚当
3 切斯特

Minus query will be,

减号查询将是,

SELECT * FROM First 
MINUS
SELECT * FROM Second;

The resultset table will look like,

结果集表如下所示:

IDNAME
1abhi
ID 名称
1个 阿比

翻译自: https://www.studytonight.com/dbms/set-operation-in-sql.php

hive sql 中的运算

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值