group by

hive中group by 提示Expression Not In Group By Key的解决办法

 

hive中group by的时候

select col_1,col_2 from table_name group by col_1;

会提示:

FAILED: SemanticException [Error 10025]: Line 1:12 Expression not in GROUP BY key ‘col_2’

这里网上查了下,有两种解决方法:

1、不关心col_2的值,且有多个col_2,那么语句改成

select col_1, collect_set( col_2 )[0] from table_name group by col_1;

2、如果每个col_2的值不同且关心col_2的值,那么可以改成

select col_1,col_2 from table_name group by col_1,col_2;

posted @ 2018-09-08 20:13  BoomOoO  阅读(186)  评论(0编辑  收藏  举报