COLLECT_SET,对于多列的group by操作时,
如果你想得到这样的结果:
appid       app_name           app_url
1                  应用汇             www.test1.com
1                  阿拉工具          www.test2.com
2                  小星星             www.test3.com
3                   小生                www.test4.com
3                  小明                  www.test5.com
希望得到这样的结果:
appid         app_name               app_url
1                 应用汇                     www.test1.com
2                 小星星                     www.test3.com
3                  小生                        www.test4.com
由于不能使用 multi-distinct, 故可以使用如下方式得到:
hive>
select appid,          
       collect_set(app_name)[0],          
       collect_set(app_url)[0]
from            
       your_table
group by            
       appid;
另一种做法:可以考虑使用min, max
select appid,  
       max(app_name),      
       max(app_url)
from     
       your_table
group by         
       appid;
详解:
| array | collect_set(col) | Returns a set of objects with duplicate elements eliminated | 
collect_set: 返回去重的元素数组。
 
--转自
