sql - Big Query 中的 STRUCT 来自另一个表
问题描述
我在 BigQuery 中有一些问题,
我有 2 张桌子第一张桌子是 paymentSchedule
ID | index_month | 数量 |
---|---|---|
啊啊啊 | 1 | 1000000 |
啊啊啊 | 2 | 2000000 |
bbb | 1 | 500000 |
bbb | 2 | 250万 |
bbb | 3 | 2000000 |
ccc | 1 | 2000000 |
第二个表是 BorrowerTable
ID | 姓名 |
---|---|
啊啊啊 | 亚历克斯 |
bbb | 若尔德 |
ccc | 胡安 |
我想使用 STRUCT 编写查询,我想要的结果是:
ID | 姓名 | index_month | 数量 |
---|---|---|---|
啊啊啊 | 亚历克斯 | 1 | 1000000 |
2 | 2000000 | ||
bbb | 若尔德 | 1 | 500000 |
2 | 250万 | ||
3 | 2000000 | ||
ccc | 胡安 | 1 | 2000000 |
我已经写了查询,但它不起作用
select *, STRUCT[select * from paymentSchedule where id=BorrowerTable.ID]from BorrowerTable
解决方案
with paymentSchedule as (
select 'aaa' as id, 1 as index_month, 1000000 as amount union all
select 'aaa', 2, 2000000 union all
select 'bbb', 1, 500000 union all
select 'bbb', 2, 25000000 union all
select 'bbb', 3, 20000000 union all
select 'ccc', 1, 20000000
),
BorrowerTable as (
select 'aaa' as id, 'Alexa' as name union all
select 'bbb', 'Jorde' union all
select 'ccc', 'Juan'
)
select *, array(select struct(index_month, amount) from paymentSchedule where id=BorrowerTable.ID)
from BorrowerTable
推荐阅读
- wcf - 无法访问 WCF 服务元数据 (wsdl):错误 400
- vb.net - 将字节转换为兆字节时的 NaN 结果
- javascript - 每次追加如何计算索引以及何时删除它可以重置js中的整个索引
- google-chrome-extension - 如何设置 chrome-extension cookie 权限
- javascript - 将 JSON 对象添加到外部文件中的现有数组
- python - 在python中运行程序时导入错误出现以下错误消息
- python - 如何将 django.contrib.auth 中的现有用户与 Python Social Auth(Google 后端)相关联?
- java - MockRestServiceServer 是否支持双向 TLS,如果支持,如何配置?
- python - Python:从 json/dictionary 创建 csv
- javascript - TypeError:无法读取未定义的属性“tapAsync”