Google Big Query Flatten table 并使用 table_range 函数

Google Big Query Flatten table and use table_range function

有谁知道如何同时使用多个 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

谢谢

在下面尝试(未测试)

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

您应该改用标准 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 之间的差异在 migration guide 中进行了描述。