0

我正在学习在 bigquery 中取消嵌套,我的理解是 UNNEST(hits) 跟在表名之后,并且在 where 子句中定义了 WHERE 子句中的 hits.type。下面的查询给出了错误无效的表名,但是表名是正确的:

SELECT index, value
FROM (SELECT hits.customDimensions.index as index,
             hits.customDimensions.value as value
      FROM `60400612.ga_sessions_*`,
            UNNEST(hits) AS hits
      WHERE _table_suffix BETWEEN '20190714' and '20190811'
         AND hits.type = 'customDimensions')
GROUP BY 1,2

我在这里想念什么?

4

2 回答 2

0

我实际上不确定范围规则是什么。但是,我认为使用相同的名称是一种不好的做法。因此,只需将其重命名为hit

FROM 60400612.ga_sessions_* CROSS JOIN
     UNNEST(hits) AS hit
WHERE  _table_suffix BETWEEN '20190714' and '20190811' AND
       hit.type = 'customDimensions'
于 2019-08-14T12:28:16.910 回答
0

This query for example does actually work (same nesting construction i used):

SELECT Source, Medium, New_Users, Sessions, ((Bounces/Sessions) * 100) AS bounce_rate
FROM(SELECT trafficSource.source AS Source, TrafficSource.medium AS medium, 
COUNT(DISTINCT fullVisitorId) AS Users, COUNT(DISTINCT(
      CASE
        WHEN totals.newVisits = 1 THEN fullVisitorId
      ELSE
      NULL
    END
      )) AS New_Users, 
COUNT(DISTINCT CONCAT(fullVisitorId, CAST(visitStartTime AS STRING))) AS Sessions, sum(totals.bounces) AS Bounces
FROM
  `60400612.ga_sessions_*`,
  UNNEST(hits) AS hits
  WHERE 
  _table_suffix BETWEEN '20190714' and '20190811'
  AND hits.type = 'PAGE'
  AND hits.page.hostname like 'xxx'
GROUP BY 1,2)
ORDER BY 4 DESC
于 2019-08-14T12:35:01.703 回答