【发布时间】:2016-02-09 11:12:04
【问题描述】:
我有一张在 Big Query 中有很多属性的表。我关心 Big Query 的两个属性。
我有
hits.eCommerceAction.action_type 、 hits.product.productSKU 和 hits.hitNumber。
写了如下代码
SELECT hits.product.productSKU as SKU,
IF(hits.eCommerceAction.action_type = '1', (hits.hitNumber), NULL) ListCLicks
IF(hits.eCommerceAction.action_type = '2', (hits.hitNumber), NULL)) PDV
FROM [107485206.ga_sessions_20160101]
where hits.eCommerceAction.action_type in ('1')
#group by SKU,ListClicks
我的问题是上面的代码返回了 hits.hitNumber 的第一个值,它是 SKU 的索引号。一个 SKU 可以有多个 hits.hitNumber。我想计算(而不是作为索引求和)SKU 的总 hits.hitNumber。
ProductSKU | PDV | ListCLicks
-------------------------
1 | 120 | 235
2 | 234 | 124
3 | 2311| 1256
4 | 12 | 34
5 | 12 | 33
2 | 112 | 345
4 | 789 | 1110
2 | 3333| 2131
当 hits.eCommerceAction.action_type = '2' 和时,PDV 是 hits.hitNumber 索引 当 hits.eCommerceAction.action_type = '1' 时,List Clicks 是 hits.hitNumber 索引
输出是
ProductSKU | PDV | ListCLicks
-------------------------
1 | 1 | 1
2 | 3 | 3
3 | 1 | 1
4 | 2 | 2
5 | 1 | 1
当 hits.eCommerceAction.action_type = '2' 和时,PDV 是 hits.hitNumber 计数 当 hits.eCommerceAction.action_type = '1' 时,List Clicks 是 hits.hitNumber 计数
我该怎么做?
【问题讨论】:
-
目前尚不清楚您的具体情况。您应该提供一些简化的输入示例和预期输出
-
@MikhailBerlyant 我添加了相同的内容。请看一看。
标签: mysql google-analytics google-bigquery