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;

http://one-line-it.blogspot.com/2012/11/hive-expression-not-in-group-by-key.html

Technorati : hadoop, hive, linux
Del.icio.us : hadoop, hive, linux
Zooomr : hadoop, hive, linux
Flickr : hadoop, hive, linux

来源URL:http://darkz.co/archives/hive-zhong-group-by-ti-shi-expression-not-in-group-by-key-de-jie-jue-ban-fa.html