我有两个表。
1.table1:(string,array(string))
abc ["s","m"]2.table2:(string,int)
def ["m","a","l"]
xyz ["s","a"]
m 12现在我想要如下表所示:(string,map(string,int))
s 26
l 57
a 45
abc ["s":26,"m":12]1.为此,我需要 HIVE 查询。
def ["m":12,"a":45,"l":57]
xyz ["s":26,"a":45]
abc 38
这样的弓形行求和
答案 0 :(得分:0)
这可以解决问题
select t1.cat, collect_list(concat_ws(":", t1.subs, cast(t2.cnt as string))) from
(select cat, subs from temp.table1
lateral view explode(sub) s as subs) t1
join
temp.table2 t2
on
t1.subs = t2.sub
group by t1.cat
如果要基于上表进行求和。
select cat, sum(split(sub, ":")[1]) from temp.test3
lateral view explode(`_c1`) c as sub
group by cat