gpt4 book ai didi

google-analytics - 无法访问类型为ARRAY >的值的字段productQuantity

转载 作者:行者123 更新时间:2023-12-03 17:25:24 24 4
gpt4 key购买 nike

我正在尝试使用BigQuery从Google Analytics(分析)中查询数据。在运行之前,它给了我这个错误:


Cannot access field productQuantity on a value with type ARRAY<STRUCT<productSKU STRING, v2ProductName STRING, v2ProductCategory STRING, ...>>


我用谷歌搜索,并且我已经按照其他答案中的建议使用了UNNEST函数。我不知道怎么了。

另外,我从Google Analytics(分析)中的不同表进行查询,并且数据按日期存储。有没有一种方法可以在不重复代码的情况下从特定时间范围进行查询?

请在下面查看我的代码:

#standardSQL
SELECT
date,
hits.transaction.transactionId,
hits.product.productQuantity
FROM
`XXX1`,
UNNEST(hits) AS hits,
UNNEST(hits.product.productQuantity) AS prod
GROUP BY
date
UNION ALL
SELECT
date,
hits.transaction.transactionId,
hits.product.productQuantity
FROM
`XXX2` UNNEST(hits) AS hits,
UNNEST(hits.product.productQuantity) AS prod
GROUP BY
date
UNION ALL
SELECT
date,
hits.transaction.transactionId,
hits.product.productQuantity
FROM
`XXX3` UNNEST(hits) AS hits,
UNNEST(hits.product.productQuantity) AS prod
GROUP BY
date
UNION ALL
SELECT
date,
hits.transaction.transactionId,
hits.product.productQuantity
FROM
`XXX4` UNNEST(hits) AS hits,
UNNEST(hits.product.productQuantity) AS prod
GROUP BY
date
UNION ALL
SELECT
date,
hits.transaction.transactionId,
hits.product.productQuantity
FROM
`XXX5` UNNEST(hits) AS hits,
UNNEST(hits.product.productQuantity) AS prod
GROUP BY
date
UNION ALL
SELECT
date,
hits.transaction.transactionId,
hits.product.productQuantity
FROM
`XXX6` UNNEST(hits) AS hits,
UNNEST(hits.product.productQuantity) AS prod
GROUP BY
date

最佳答案

无法访问类型为ARRAY>的值的字段productQuantity


您应该使用以下方法

#standardSQL
SELECT
date,
hits.transaction.transactionId,
prod.productQuantity
FROM `XXX`,
UNNEST(hits) AS hits,
UNNEST(hits.product) AS prod


因此,如您所见,使用未嵌套的“ prod”访问 productQuantity

注意:当您使用GROUP BY时,您需要对select语句中不属于GROUP BY的那些文件使用聚合函数-在您的示例中,下面的两个字段需要与您要查找的任何聚合一起应用如果您仍然需要GROUP BY

hits.transaction.transactionId, 
prod.productQuantity



有没有一种方法可以在不重复代码的情况下从特定时间范围进行查询?


是的,您可以为此使用 _TABLE_SUFFIX

像下面的例子

#standardSQL
SELECT
date,
hits.transaction.transactionId,
prod.productQuantity
FROM `project.dataset.XXX*`,
UNNEST(hits) AS hits,
UNNEST(hits.product) AS prod
WHERE _TABLE_SUFFIX BETWEEN '1' AND '6'

关于google-analytics - 无法访问类型为ARRAY <STRUCT <productSKU STRING,v2ProductName STRING,v2ProductCategory STRING,…>>的值的字段productQuantity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56064580/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com