无法使用WHERE进行过滤(无法访问类型为ARRAY <struct <hitnumber int64,=“”time =“”int64,=“”hour =“”int64“

时间:2018-06-16 15:03:50

标签: sql google-bigquery standards

2 个答案:

答案 0 :(得分:2)

您可以使用以下方法修复语法:

SELECT DISTINCT geoNetwork.country
FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*`
WHERE _TABLE_SUFFIX BETWEEN '20170701' AND '20170701' AND
      hits[offset(0)].hour > 11

但那并不能真正做到你想要的。相反,您需要unnest(),因为hits是一个数组。所以:

SELECT DISTINCT geoNetwork.country
FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*`,
     unnest(hits) hit
WHERE _TABLE_SUFFIX BETWEEN '20170701' AND '20170701' and
      hit.hour > 11;

另请注意,hour似乎是一个数字,因此单引号不合适。

答案 1 :(得分:2)

#standardSQL
SELECT DISTINCT geoNetwork.country
FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*`
WHERE _TABLE_SUFFIX BETWEEN '20170701' AND '20170701' 
AND EXISTS (SELECT 1 FROM UNNEST(hits) hit WHERE hit.hour > 11)