我有一个表,看起来像这样:
text | STRING
concepts | RECORD
concepts.name | STRING
[...]因此,一行可能如下所示:
"This is a text about BigQuery and how to split records into columns. "
SQL
BigQuery
Questions我想将其转化为:
text, concepts_1, concepts_2, concepts_3 // The names are not important
"This is a text about BigQuery and how to split records into columns. ",SQL,BigQuery,Questions每一行中的概念数量各不相同。
编辑:
这也是可行的:
text, concepts
"This is a text about BigQuery and how to split records into columns. ","SQL,BigQuery,Questions"发布于 2019-12-05 23:59:56
下面是针对BigQuery标准SQL的说明
如果逗号分隔的列表对你来说很好-考虑下面的快捷方式版本
#standardSQL
SELECT identifier,
(SELECT STRING_AGG(name, ', ') FROM UNNEST(concepts)) AS conceptName
FROM `project.dataset.articles` 和
#standardSQL
SELECT identifier,
(SELECT STRING_AGG(name, ', ') FROM articles.concepts) AS conceptName
FROM `project.dataset.articles` articles 以上两个版本都返回如下输出
Row identifier conceptName
1 1 SQL, BigQuery, Questions
2 2 xxx, yyy, zzz 正如你所看到的-上面的版本是简短紧凑的,没有使用额外的分组来数组,然后将其转换为字符串-因为所有这些都可以在一个简单的快照中完成
发布于 2019-12-05 23:34:50
这就是我的解决方案。但它只创建一个逗号分隔的字符串。然而,在我的例子中,这是很好的。
SELECT articles.identifier, ARRAY_TO_STRING(ARRAY_AGG(concepts.name), ",") as
conceptName
FROM `` articles, UNNEST(concepts) concepts
GROUP BY articles.identifier发布于 2019-12-05 23:35:02
尝试使用以下命令:
SELECT
text,
c.*
FROM
`your_project.your_dataset.your_table`,
UNNEST(
concepts
) c这将获得文本列以及记录列中未嵌套的值。
希望能有所帮助。
https://stackoverflow.com/questions/59195956
复制相似问题