sql - 我需要创建一个新列或从数组更改原始列映射其中 int 值在相应字符串的新表中
问题描述
我有两张桌子。
1.table1:(字符串,数组(字符串))
abc ["s","m"]2.table2:(字符串,整数)
def ["m","a","l"]
xyz ["s","a"]
米 12现在我想要一个如下表:(string,map(string,int))
秒 26
升 57
一个 45
abc ["s":26,"m":12]1. 我需要HIVE查询来执行此操作。
def ["m":12,"a":45,"l":57]
xyz ["s":26,"a":45]
2.如何为特定的行总和进行交互,例如
美国广播公司 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
推荐阅读
- amazon-ec2 - zmq.error.ZMQError:无法分配请求的地址
- node.js - 在节点js中将pdf文件转换为svg
- r - 在 R 3.4.4 和 R 3.5 中与 deparse 不同的结果
- node.js - Node.js 未在 Windows 4 月 10 日更新上安装
- java - 使用 sparkexcel 库读取重复的列名 excel 文件时出现异常。如何克服这个问题
- c# - 如何在控制器中检索动作链接文本?
- email - 如何使用 ICS 文件在 Google 日历中添加/修改事件
- android - setUserVisibleHint 调用了两次
- python - 如何使另一个函数中的函数同时退出两个函数?
- java - Google 服务 3.3.0 升级错误 - 多个项目匹配变体