2

我绝不是编码员,所以我尝试过但在这方面失败了。

我想使用 Googles Google Analytics Big Query Cookbook 中的这个查询

购买产品 A 的客户购买的产品(增强型电子商务)

我已经粘贴了下面的代码

进入标准 SQL。

我做了几次尝试,但我摔倒了

提前谢谢你,约翰

SELECT hits.product.productSKU AS other_purchased_products, 
  COUNT(hits.product.productSKU) AS quantity
FROM (
  SELECT fullVisitorId, hits.product.productSKU, hits.eCommerceAction.action_type 
    FROM TABLE_DATE_RANGE([bigquery-public-data:google_analytics_sample.ga_sessions_],
                          TIMESTAMP('2017-04-01'), TIMESTAMP('2017-04-20'))
)
WHERE fullVisitorId IN (
  SELECT fullVisitorId
    FROM TABLE_DATE_RANGE([bigquery-public-data:google_analytics_sample.ga_sessions_],
                          TIMESTAMP('2017-04-01'), TIMESTAMP('2017-04-20'))
    WHERE hits.product.productSKU CONTAINS 'GGOEYOCR077799'
    AND hits.eCommerceAction.action_type = '6'
    GROUP BY fullVisitorId 
)
AND hits.product.productSKU IS NOT NULL
AND hits.product.productSKU !='GGOEYOCR077799'
AND hits.eCommerceAction.action_type = '6'
GROUP BY other_purchased_products
ORDER BY quantity DESC;
4

1 回答 1

1

以下是 BigQuery 标准 SQL 中的纯等价物(没有任何优化、改进等 - 只是从旧版到标准的纯转换)

SELECT productSKU AS other_purchased_products, COUNT(productSKU) AS quantity
FROM (
  SELECT fullVisitorId, prod.productSKU, hit.eCommerceAction.action_type 
  FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*`,
  UNNEST(hits) hit, UNNEST(hit.product) prod
  WHERE _TABLE_SUFFIX BETWEEN '20170401' AND '20170420'
)
WHERE fullVisitorId IN (
  SELECT fullVisitorId
  FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*`,
  UNNEST(hits) hit, UNNEST(hit.product) prod
  WHERE _TABLE_SUFFIX BETWEEN '20170401' AND '20170420'
  AND prod.productSKU LIKE '%GGOEYOCR077799%'
  AND hit.eCommerceAction.action_type = '6'
  GROUP BY fullVisitorId 
)
AND productSKU IS NOT NULL
AND productSKU !='GGOEYOCR077799'
AND action_type = '6'
GROUP BY other_purchased_products
ORDER BY quantity DESC 

显然产生与旧版本完全相同的结果

于 2019-08-28T01:57:42.197 回答