在sql中将多列合并为一列

n9vozmp4  于 2021-08-01  发布在  Java
关注(0)|答案(2)|浏览(466)
name       A.subject     A.grade
Michael     Math             69
Michael     Natural Sciences 43

name      B.subject    B.grade
Michael     History         99
Michael     Geography       23

name       subject         grade
Michael     Math             69
Michael     Natural Sciences 43
Michael     History          99
Michael     Geography        23

如何在hivesql中实现它?谢谢。。。。。。。。。。。。。。。。。。。。

goqiplq2

goqiplq21#

你可以用 union all ```
select
name,
a.subject,
a.grade
from yourTableA a
union all
select
name,
b.subject,
b.grade
from yourTableB b

t9eec4r0

t9eec4r02#

使用 Union ALL ```
select name, A.subject, A.grade from tablename A
union all
select name, B.subject, B.grade from tablename B

相关问题