简体   繁体   English

如何在 HiveSQL 中进行 vlookup?

[英]How to do vlookup in HiveSQL?

I'm new to Hive and still learning about it, but have a small problem here.我是 Hive 的新手,仍在学习它,但这里有一个小问题。 Really need help on this thing..在这件事上真的需要帮助..

So, I have a table of students' grade as below:所以,我有一张学生成绩表,如下所示:

成绩表

*exam_index shows how many exams each student have taken, 1 means first exam, 2 means second exam. *exam_index 显示每个学生参加了多少次考试,1 表示第一次考试,2 表示第二次考试。

and I'd like to convert it into this expected result:我想把它转换成这个预期的结果:

结果表

Any idea of doing this?有这样做的想法吗? Any input would be greatly appreciated.任何投入将不胜感激。 Thanks!谢谢!

You can use conditional aggregation:您可以使用条件聚合:

select student,
       max(case when exam_index = 1 then grade end) as grade_1,
       max(case when exam_index = 2 then grade end) as grade_2
from t
group by student;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM