sql - 更新 SQL - 还购买了产品
问题描述
使用 BigQuery 食谱中的此查询,并添加到 _table_date_range_ 中,因为我想查询不止一天。
该查询查找产品并返回与该产品一起购买的其他产品。
SELECT hits.item.productName AS other_purchased_products, COUNT(hits.item.productName) AS quantity
FROM (TABLE_DATE_RANGE([ghd-analytics-xxxxxx.xxxxxx.ga_sessions_],
TIMESTAMP('2018-08-01'), TIMESTAMP('2018-09-31')))
WHERE fullVisitorId IN (
SELECT fullVisitorId
FROM (TABLE_DATE_RANGE([ghd-analytics-xxxxxx.xxxxxx.ga_sessions_],
TIMESTAMP('2018-08-01'), TIMESTAMP('2018-08-03')))
WHERE hits.item.productName CONTAINS 'productA'
AND totals.transactions>=1
GROUP BY fullVisitorId )
AND hits.item.productName IS NOT NULL
AND hits.item.productName !='productA'
GROUP BY other_purchased_products
ORDER BY quantity DESC;
错误信息:
(L2:1):JOIN(包括半连接)和 UNION ALL(逗号,日期范围)不能组合在一个 SELECT 语句中。将 UNION ALL 移动到内部查询或将 JOIN 移动到外部查询。
我不知道该怎么做它的建议!
非常感谢您的帮助。
解决方案
我不知道该怎么做它的建议!
您只是按照错误声明中的建议进行操作 -move the UNION ALL to an inner query
所以,在下面的固定版本中 - 我刚刚SELECT * FROM
在第二行 添加
SELECT hits.item.productName AS other_purchased_products, COUNT(hits.item.productName) AS quantity
FROM (SELECT * FROM TABLE_DATE_RANGE([ghd-analytics-xxxxxx.xxxxxx.ga_sessions_],
TIMESTAMP('2018-08-01'), TIMESTAMP('2018-09-31')))
WHERE fullVisitorId IN (
SELECT fullVisitorId
FROM (TABLE_DATE_RANGE([ghd-analytics-xxxxxx.xxxxxx.ga_sessions_],
TIMESTAMP('2018-08-01'), TIMESTAMP('2018-08-03')))
WHERE hits.item.productName CONTAINS 'productA'
AND totals.transactions>=1
GROUP BY fullVisitorId )
AND hits.item.productName IS NOT NULL
AND hits.item.productName !='productA'
GROUP BY other_purchased_products
ORDER BY quantity DESC
注意:我希望你有充分的理由在这里使用 Legacy SQL - 无论如何考虑迁移到标准 SQL
推荐阅读
- tensorflow - 在视频流中检测到对象后,我想裁剪并保存这些对象
- lambda - 如何使用 lambda Dsl for Pact 为“arrayMinLike”生成相同的匹配规则?
- botframework - 如何在 Microsoft Bot Framwork 中使用 C# 将 Chatbot 集成到 Skype for business On Premises
- javascript - 如何从 Javascript 函数执行 Angular 函数?
- python - 在peewee(sqlite3)中按binned列分区
- java - 无法在 Android WebView 中获取 cookie 数据
- html - 在angularjs中配置文本标签
- networking - 从快照创建的 Google Cloud 虚拟机实例不允许 ssh
- html - 将 html 转换为画布然后转换为 Pdf 时分页符不起作用
- android - 如何在 Volley 中使用 Post 方法?