hiveql查询选择classid,studname,table1的studname,classid,studname classID;
很抱歉在主题上写了一个明显的不良查询,但它准确地描述了我想要的结果。
我有一个带有classid int,studname string,grade int的表。我需要一个结果,列出了每个课程中获得最高成绩的每个类别的studname。多个学生可以达到成绩,每个学生应首先按ClassID列出,然后由StudName列出。
样本输出: | classid | StudName | | ---------- | ----------- | | 101 |玛丽| | 101 | Nate | | 101 |克里斯| | 102 |本杰明| | 103 | Nate | | 103 |汤姆| etc...
my first guess is:
SELECT classID, studName from table1 where grade = MAX(grade) group by classID, studName;
but this gives an error: ... not yet supported place for UDAF 'max'
I have also tried creating a view:
CREATE VIEW newView as select classID, MAX(grade) from table1 group by classID;
and using it in a subquery in the where statement:
select classID, studName from table1 where grade IN (select * from newView) group by classID, studName;
but it seems that : "SubQuery can contain only 1 item in SELECT List"
I have poured over "Apache Hive Essentials" book with no luck either.
我是Hiveql的新手,这让我在晚上起床。任何帮助将不胜感激。
谢谢
Sorry for writing an obvious bad query in subject but it accurately describes the result I am looking for.
I have a table with classID int, studName string, grade int. I need a result that lists each classID, studName that achieved the highest grade in each course. multiple students can achieve the grade and each should be listed in descending order first by classID then by studName.
sample output:
| classID | studName|
|---------|---------|
| 101 | Mary |
| 101 |Nate |
| 101 |Chris |
| 102 |Benjamin |
| 103 |Nate |
|103 |Tom |
etc...
my first guess is:
SELECT classID, studName from table1 where grade = MAX(grade) group by classID, studName;
but this gives an error:
... not yet supported place for UDAF 'max'
I have also tried creating a view:
CREATE VIEW newView as select classID, MAX(grade) from table1 group by classID;
and using it in a subquery in the where statement:
select classID, studName from table1 where grade IN (select * from newView) group by classID, studName;
but it seems that :
"SubQuery can contain only 1 item in SELECT List"
I have poured over "Apache Hive Essentials" book with no luck either.
I am new to HiveQL and this one is keeping me up at night. Any help would be GREATLY appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的SQL -
您需要命名最大列,然后在子句中的子查询中使用它。
更改下面的视图。
更改您的SQL
解决方案
但是,此SQL将通过调整您的SQL来帮助您实现“在每个主题中获得最高成绩的学生”所需的目标。
Issue with your SQL -
You need to name the max column and then use it in subquery IN clause.
change the view like below.
Change your SQL like this
Solution
But this SQL will help you in achieving what you need 'find students who got max grade in each subject' by tweaking your SQL.