Google Big Query Flatten表并使用table_range函数

时间:2017-01-10 01:39:53

标签: google-bigquery flatten

有谁知道如何同时使用多个FLATTEN函数和Table_date_range?现在我只能获得一天的数据,但我希望获得所有可用的数据。有办法吗?

select 
Date,COUNT(DISTINCT FULLVISITORID),hits.product.v2ProductCategory
FROM FLATTEN((FLATTEN (table, hits.product.v2ProductCategory)) ,customDimensions.value)
group by Date
,hits.product.v2ProductCategory

谢谢

2 个答案:

答案 0 :(得分:5)

您应该使用标准SQL。例如,

#standardSQL
SELECT
  Date,
  COUNT(DISTINCT FULLVISITORID),
  product.v2ProductCategory,
  customDimension.value
FROM `aaprod-20160309.112099209.ga_sessions_*` AS t
  CROSS JOIN UNNEST(hits) AS hit
  CROSS JOIN UNNEST(t.customDimensions) AS customDimension
  CROSS JOIN UNNEST(hit.product) AS product
GROUP BY 1, 3, 4;

遗留标准SQL与标准SQL之间的差异在migration guide

中有所描述

答案 1 :(得分:2)

尝试以下(未测试)

SELECT 
  DATE,
  COUNT(DISTINCT FULLVISITORID),
  hits.product.v2ProductCategory
FROM FLATTEN(FLATTEN (
  (SELECT * 
  FROM TABLE_DATE_RANGE([aaprod-20160309:112099209.ga_sessions_],
        TIMESTAMP('2016-07-25'),
        TIMESTAMP('2016-07-27'))
  ), hits.product.v2ProductCategory), customDimensions.value
)
GROUP BY 
  DATE, 
  hits.product.v2ProductCategory