簡體   English   中英

我需要創建一個新列或從數組中更改原始列 <string> 來圖 <string,int> 其中int值在相應字符串的新表中

[英]I need to create a new column or alter the original from array<string> to map<string,int> where int values are in new table for respective string

我有兩張桌子。
1.table1:(字符串,陣列(字符串))

abc ["s","m"]
def ["m","a","l"]
xyz ["s","a"]
2.table2:(字符串,整數)
  12 
s 26
l 57
45
現在我想要一個如下表:( string,map(string,int))
  abc [“s”:26,“m”:12] 
def [“m”:12,“a”:45,“l”:57]
xyz [“s”:26,“a”:45]
我這樣做需要HIVE查詢。
2.如何與一個特定的行總和相互作用
  abc 38 

這樣就可以了

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM