我希望将以下旧版 SQL 查询转换为标准 SQL。我遇到的问题是我需要取消嵌套两个表(标签和学分)。如何转换此查询?谢谢!
每当我尝试重写此查询时,都会遇到“标量子查询产生了多个元素”(见下文)。
我正在尝试重写的旧版 SQL 查询:
SELECT
service.description,
sku.description,
usage_start_time,
usage_end_time,
labels.key,
labels.value,
cost,
usage.amount,
project.name,
credits.name,
credits.amount
FROM
flatten([gcp_billing_data.gcp_billing_export],
credits)
到目前为止我在标准 SQL 中尝试过的内容:
SELECT
service.description AS service,
sku.description AS sku,
usage_start_time,
usage_end_time,
l.key,
l.value,
cost,
usage.amount AS usage,
project.name AS project,
c.name AS credit,
c.amount
FROM
`gcp_billing_data.gcp_billing_export`,
UNNEST(labels) AS l,
UNNEST(credits) AS c
Group by 1,2,3,4,5,7,8,9,10,11
此查询运行,但行数明显少于我的预期。