使用 Hive 将列转换为同一 table 中的行
Transposing columns to rows in the same table using Hive
这道题是 题的延续。
我有以下 table :
EmployeeId Dept1 Dept2 Dept3
150 10 55 6
这是获得该结果的查询:
SELECT EmployeeId, Dept1, Dept2, Dept3 FROM Employee_History
这是我的预期输出:
EmployeeId Dept
150 10
150 55
150 6
虽然 Hive 不支持 PIVOT 和 UNPIVOT 查询,但您可以使用以下内容:
select EmployeeId
,pe.val as Dept
from Employee_History
lateral view posexplode(array(dept1,dept2,dept3)) pe
;
这道题是
我有以下 table :
EmployeeId Dept1 Dept2 Dept3
150 10 55 6
这是获得该结果的查询:
SELECT EmployeeId, Dept1, Dept2, Dept3 FROM Employee_History
这是我的预期输出:
EmployeeId Dept
150 10
150 55
150 6
虽然 Hive 不支持 PIVOT 和 UNPIVOT 查询,但您可以使用以下内容:
select EmployeeId
,pe.val as Dept
from Employee_History
lateral view posexplode(array(dept1,dept2,dept3)) pe
;