snowflake-cloud-data-platform - 横向展平雪花中具有不同阵列长度的两列
问题描述
我是雪花的新手,目前正在学习使用横向扁平化。
用于“Customer_Number”和“Cities”的数据类型是数组。
我已经设法理解并应用 Flatten 概念来使用以下 sql 语句来分解数据:
select c.customer_id, c.last_name, f.value as cust_num, f1.value as city
from customers as c,
lateral flatten(input => c.customer_number) f,
lateral flatten(input => c.cities) f1
where f.index = f1.index
order by customer_id;
从虚拟表中我们可以清楚地看到,在第 4 行 customer_id 104 有 3 个数字,我想在我的输出中看到这三个数字,如果城市中没有匹配的索引值,我只想看到“Null”在“城市”。
解决方案
诀窍是删除第二个横向,并使用第一个的索引从第二个数组中选择值:
select c.customer_id, c.last_name, f.value as cust_num, cites[f.index] as city
from customers as c,
lateral flatten(input => c.customer_number) f
order by customer_id;
推荐阅读
- javascript - Nodemailer OAuth2 2LO 在 Heroku 部署中失败
- r - 如何删除特定行并保留名称?
- python - split('@') 中的 @ 除了作为字符串分隔符之外还有什么作用?
- firebase - 如何处理 Cloud Flutter Firestore 中的嵌套集合查询?
- elasticsearch - 重新索引弹性搜索不会返回所有文档
- sql - 如何使用窗口函数向我的 SQL 查询添加新的计算列?
- javascript - getElementsByClassName 参考
- python - 两个轴上带有 pandas DateTimeIndex 的热图
- java - 有什么方法可以将这些嵌套的 IntStream 合并为一个吗?有更短的方法吗?
- reactjs - 对 reactjs 应用程序的挂载路径所做的更改不会反映在 Web UI 中