Query hits and custom dimensions in the BigQuery?

假如想象 提交于 2019-12-06 12:11:56

问题


I am working with the GoogleAnalytics data in the BigQuery. I want to output 2 columns: specific event actions (hits) and custom dimension (session based). All that, using Standard SQL. I cannot figure out how to do it correctly. Documentation does not help either. Please help me. This is what I am trying:

SELECT
  (SELECT MAX(IF(index=80, value, NULL)) FROM UNNEST(customDimensions)) AS is_app,
  (SELECT hits.eventInfo.eventAction) AS ea
FROM  
  `table-big-query.105229861.ga_sessions_201711*`, UNNEST(hits) hits
WHERE 
  totals.visits = 1
  AND _TABLE_SUFFIX BETWEEN '21' and '21'
  AND EXISTS(SELECT 1 FROM UNNEST(hits) hits
    WHERE hits.eventInfo.eventCategory = 'SomeEventCategory'
  )

回答1:


Try to give your tables and sub-tables names that are not part of the original table schema. Always tell to which table you're referring - when cross joining, you're basically adding new columns (here h.* - flattened) - but the old ones (hits.* - nested) still exist. I named ga_sessions_* t and use it to refer the cross-join and also the customDimension.

Also: You don't need the legacy sql trick using MAX() for customDimensions anymore. It's a simple sub-query now :)

try:

SELECT
  (SELECT  value FROM t.customDimensions where index=80) AS is_app, -- use h.customDimensions if it is hit-scope
  eventInfo.eventAction AS ea
FROM  
  `projectid.dataset.ga_sessions_201711*` t, t.hits h
WHERE 
  totals.visits = 1
  AND _TABLE_SUFFIX BETWEEN '21' and '21'
  AND h.eventInfo.eventCategory is not null


来源:https://stackoverflow.com/questions/48117541/query-hits-and-custom-dimensions-in-the-bigquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!