sql - 连接 Google Big Query 中的重复记录
问题描述
我有以下 JSON 结构中存在的数据
{"person": "John", "children": [{"name":"Tim", "age":9},{"name":"Suszan", "age":12},{"name":"Karl", "age":14}]}
在 Big Query 中,它有 schmea
children RECORD REPEATED
children. age INTEGER NULLABLE
children. name STRING NULLABLE
person STRING NULLABLE
当我们查看实际表时,我们有这个
但我真的很想拥有以下格式的数据
我被卡住unnest(children) as children
了,因为我知道我可以用来访问记录,但它会创建一个新行,但我不能使用ARRAY_TO_STRING(children.name)
,因为它不是纯粹的数组。我有点夹在两者之间。
谢谢你。
解决方案
您应该能够访问元素并聚合:
select t.person, string_agg(child, ',')
from t cross join
unnest(children) child
group by t.person;
推荐阅读
- c# - 如何使用 C# 在 Active Directory 用户路径中使用 %username% 变量?
- javascript - 为什么 document.GetElementsByClassName() for loop 缺少一些元素?
- unity3d - 使用 Unity3D 更新 ParticleEmitter 引用
- reactjs - ReactJS:不能随着状态的变化而改变样式
- javascript - 是什么阻止了 jQuery .click() 函数的执行?
- graph - 通过TSP的路线检查/中国邮递员问题
- django-models - 我应该在模型中使用什么页面,或者我应该只将它用作模板?
- javascript - 如何根据父级的当前拖动位置平移视图偏移
- reactjs - 无法覆盖深度嵌套组件的样式(Material-UI Jss 样式)
- java - Batch Status 卡在 STARTING 状态,