如何从 BigQuery 获取基于时间的结果?
Posted
技术标签:
【中文标题】如何从 BigQuery 获取基于时间的结果?【英文标题】:How to get results based on time from BigQuery? 【发布时间】:2020-05-25 05:54:42 【问题描述】:我需要获取特定时间范围内的数据。目前,我只能根据日期获取数据。如何获取相同日期范围但时间范围为下午 3 点到 5 点的数据?
SELECT
event_name,
COUNT(DISTINCT user_pseudo_id) as uniques,
COUNT(user_pseudo_id) as total
FROM
`XYZ.analytics_123.events_*`
WHERE
app_info.install_source = "iTunes"
AND (Extract (DATE FROM TIMESTAMP_MICROS( user_first_touch_timestamp )) between "2020-05-20" and
"2020-05-20")
AND (_TABLE_SUFFIX between "20200520" AND "20200520")
GROUP BY
event_name
【问题讨论】:
【参考方案1】:您可以使用EXTRACT(HOUR FROM TIMESTAMP_MICROS(user_first_touch_timestamp )) BETWEEN 15 AND 17
,如下例所示
#standardSQL
SELECT
event_name,
COUNT(DISTINCT user_pseudo_id) AS uniques,
COUNT(user_pseudo_id) AS total
FROM `XYZ.analytics_123.events_*`
WHERE app_info.install_source = "iTunes"
AND (EXTRACT (DATE FROM TIMESTAMP_MICROS(user_first_touch_timestamp )) BETWEEN "2020-05-20" AND "2020-05-20")
AND (_TABLE_SUFFIX BETWEEN "20200520" AND "20200520")
AND (EXTRACT(HOUR FROM TIMESTAMP_MICROS(user_first_touch_timestamp )) BETWEEN 15 AND 17)
GROUP BY event_name
【讨论】:
以上是关于如何从 BigQuery 获取基于时间的结果?的主要内容,如果未能解决你的问题,请参考以下文章
如何避免 BigQuery 中的 Power BI 增量刷新重复查询?
从BigQuery数据查询中查询名为chartio的BI工具时的最大数据大小是多少?