码迷,mamicode.com
首页 > 其他好文 > 详细

Hive 的collect_set使用详解

时间:2018-08-16 19:51:18      阅读:1200      评论:0      收藏:0      [点我收藏+]

标签:statistic   tle   head   -name   view   log   下标   元素   net   

Hive 的collect_set使用详解

  select a,collect_set(b) as bb from t where b<=‘xxxxxx‘ group by a

会按照a分组 通过collect_set会把每个a所对应的b构建成一个以逗号分隔的数组返回。上述SQL返回:

a1,["b1","b2"]

a2,["b1","b2","b3","b4"] 

 可以按照这个返回的数组做文章,即为

select * from (select a,collect_set(b) as bb from t where b<=‘xxxxxx‘ group by a)  where size(tmp.bb)=1 and tmp.bb[0]=‘xxxxxxxx‘;

表示某bb所对应的数组长度为1 并且第一个bb为xxxxxxxx的a

Hive 的collect_set使用详解

标签:statistic   tle   head   -name   view   log   下标   元素   net   

原文地址:https://www.cnblogs.com/wingler/p/9488786.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!