【问题标题】:Find the Count of a property for a particular condition in Table in Big Query在 Big Query 的表中查找特定条件的属性计数
【发布时间】: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


【解决方案1】:

我假设您想按类型计算电子商务操作的数量。如果是这样,您可以使用 SUM 来完成此操作,每个相关操作添加 1,否则为 0:

SELECT hits.product.productSKU as SKU,
  SUM(IF(hits.eCommerceAction.action_type = '1', 1, 0)) ListCLicks, 
  SUM(IF(hits.eCommerceAction.action_type = '2', 1, 0)) PDV
FROM [107485206.ga_sessions_20160101]
GROUP BY SKU 

【讨论】:

    猜你喜欢
    • 2017-08-30
    • 1970-01-01
    • 2021-02-01
    • 2020-07-24
    • 2023-03-03
    • 2012-10-21
    • 2017-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多