我试图在BigQuery中选择event_dim.date
但由于错误而无法实际访问它
Error: Cannot access field date on a value with type ARRAY<STRUCT<date STRING, name STRING, params ARRAY<STRUCT<key STRING, value STRUCT<string_value STRING, int_value INT64, float_value FLOAT, ...>>>, ...>> at [1:18]
我的查询:
SELECT event_dim.date FROM `table`
我知道我做错了什么,非常感谢任何帮助。谢谢!
答案 0 :(得分:5)
您是否想要获取每行的日期数组?然后你想要一个ARRAY子查询:
SELECT ARRAY(SELECT date FROM UNNEST(event_dim)) AS dates
FROM `table`;
如果您尝试将所有日期分别放在单独的行中,那么您希望与数组交叉连接:
SELECT event.date
FROM `table`
CROSS JOIN UNNEST(event_dim) AS event;
过滤特定日期:
SELECT event.date
FROM `table`
CROSS JOIN UNNEST(event_dim) AS event
WHERE event.date = '20170104';
或者您可以将日期字符串解析为date
类型,这样您就可以过滤年份或周,例如:
SELECT date
FROM (
SELECT PARSE_DATE('%Y%m%d', event.date) AS date
FROM `table`
CROSS JOIN UNNEST(event_dim) AS event
)
WHERE EXTRACT(YEAR FROM date) = 2017;