【问题标题】:Unnesting the custom dimensions is duplicating/inflating transaction revenue in BigQuery取消嵌套自定义维度会复制/夸大 BigQuery 中的交易收入
【发布时间】:2018-06-15 16:21:09
【问题描述】:

取消嵌套 hits.customdimension 和 hits.product.customdimension 会夸大交易收入

SELECT
     sum(totals.totalTransactionRevenue)/1000000 as revenue,
     (SELECT MAX(IF(index=10,value,NULL)) FROM UNNEST(product.customDimensions)) AS product_CD10,
     (SELECT MAX(IF(index=1,value,NULL)) FROM UNNEST(hits.customDimensions)) AS CD1
    FROM
      `XXXXXXXXXXXXXXX.ga_sessions_*`, 
      UNNEST(hits) AS hits, 
      UNNEST(hits.product) as product
     WHERE
      _TABLE_SUFFIX BETWEEN "20180608"
      AND "20180608"
      group by product_CD10,CD1

有没有一种方法可以让我得到一个平面表,如果我应用收入总和,它应该给出正确的结果。

【问题讨论】:

    标签: google-analytics google-bigquery


    【解决方案1】:

    将您的 UNNEST() 移动到顶部子查询 - 这样行就不会重复:

    SELECT row
     ,  (SELECT MAX(letter) FROM UNNEST(row), UNNEST(qq)) max_letter
     ,  (SELECT MAX(n) FROM UNNEST(row), UNNEST(qq), UNNEST(qb) n) max_number
    FROM (
      SELECT [
        STRUCT(1 AS p,[STRUCT('a' AS letter, [4,5,6] AS qb)] AS qq)
        , STRUCT(2,[STRUCT('b', [7,8,9])])
        , STRUCT(3,[STRUCT('c', [10,11,12])])
       ] AS row
    )
    

    尚未对此进行测试:

    SELECT
     sum(totals.totalTransactionRevenue)/1000000 as revenue,
     (SELECT MAX(IF(index=10,value,NULL)) FROM UNNEST(hits) AS hit, UNNEST(hit.products) product,  UNNEST(product.customDimensions)) AS product_CD10,
     (SELECT MAX(IF(index=1,value,NULL)) FROM UNNEST(hits) AS hit, UNNEST(hit.customDimensions)) AS CD1
    FROM `XXXXXXXXXXXXXXX.ga_sessions_*`, 
    WHERE _TABLE_SUFFIX BETWEEN "20180608" AND "20180608"
    group by product_CD10,CD1
    

    【讨论】:

    • 感谢您的来信。如果有效,请接受答案:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多