BigQuery产品级自定义维度

时间:2016-10-18 12:07:04

标签: sql google-bigquery

我正在尝试从GA查询基本的productlevel维度,并结合产品级别的自定义维度,我无法让它工作:( 任何帮助和/或建议都非常欢迎! (当前查询如下)

SELECT
  date,
  hits.product.v2ProductName AS productName,
  hits.product.productSKU AS SKU,
  MAX(IF(hits.product.customDimensions.index=126,hits.product.customDimensions.value, null)) WITHIN hits AS customDimesion126,
  COUNT(hits.transaction.transactionId)
FROM
  TABLE_DATE_RANGE([XXX.ga_sessions_],TIMESTAMP('2016-10-16'), TIMESTAMP('2016-10-16'))

WHERE
  hits.transaction.transactionId IS NOT NULL
  
GROUP BY
  date,
  productName,
  SKU

2 个答案:

答案 0 :(得分:0)

我无法访问具有完全相同模式的表,以便能够尝试这一点,但这样的查询是否有效?您需要启用standard SQL才能运行它(取消选中“显示选项”下的“使用旧版SQL”):

SELECT
  date,
  hits.product.v2ProductName AS productName,
  hits.product.productSKU AS SKU,
  (SELECT value
   FROM UNNEST(hits.product.customDimensions)
   WHERE index=126) AS customDimension126,
  COUNT(*)
FROM
  `your-dataset.ga_sessions_*` t, t.hits hits
WHERE
  _PARTITION_TIME = '2016-10-16' AND
  hits.transaction.transactionId IS NOT NULL
GROUP BY
  date,
  productName,
  SKU;

答案 1 :(得分:0)

同样在这里 - 我无法访问具有相同模式的表格以便能够尝试这一点 - 所以下面是空中拍摄:o)

对于BigQuery Legacy SQL - 因为我想尽可能保留原始查询

SELECT
  DATE,
  productName,
  SKU,
  customDimesion126,
  SUM(cnt) AS transactions
FROM (
  SELECT
    DATE,
    hits.product.v2ProductName AS productName,
    hits.product.productSKU AS SKU,
    MAX(IF(hits.product.customDimensions.index=126,hits.product.customDimensions.value, NULL)) WITHIN hits AS customDimesion126,
    COUNT(hits.transaction.transactionId) WITHIN hits AS cnt
  FROM
    TABLE_DATE_RANGE([XXX.ga_sessions_],TIMESTAMP('2016-10-16'), TIMESTAMP('2016-10-16'))
  WHERE
    hits.transaction.transactionId IS NOT NULL
)  
GROUP BY
  DATE,
  productName,
  SKU,
  customDimesion126