【发布时间】:2021-09-30 04:11:35
【问题描述】:
我的数据库表中有一个 JSON,如下表所示,假设列包含一个名为收藏夹的 JSON 文件。
{
"info": {
"music": [{"Year":2021,"Name":"Stay","Singer":"Justin Bieber"},
{"Year":2015,"Name":"Love Yourself","Singer":"Justin Bieber"},
{"Year":2003,"Name":"Crazy In Love","Singer":"Beyonce"}
],
"movie": [{"Year":2018,"Name":"Green Book","Director":"Peter Farrelly"},
{"Year":2007,"Name":"Lust, Caution","Director":"Ang Lee"}
]
}
}
I wanted to select all values from tags and my expected table would be like as following:
-----------------------------------------------------------------------------
| Name | Singer |
----------------------------------------------------------------------------
| Stay,Love Yourself,Crazy In Love | Justin Bieber,Justin Bieber,Beyonce|
-----------------------------------------------------------------------------
我已经知道如何使用 JSON_QUERY(json_col,'$.info.music[0].Name') 获取数组中的第一个值,但我想将所有名称或歌手提取到一个单独的列中,有些数组可能有多个项目。有人有什么建议吗?
【问题讨论】:
-
"movie"之前是否缺少逗号? -
是的,感谢您的关注!
标签: sql json google-bigquery