I have some experience with MongoDB and I\'m learning about BigQuery. I\'m trying to perform the following task, and I don\'t know how to do it using BigQuery\'s standard SQ
Below is for BigQuery Standard SQL (see Enabling Standard SQL
I am using ts
as a field name (instead timestamp
as it is in your example) and assume this field is of TIMESTAMP
data type
WITH dailyAggregations AS (
SELECT
DATE(ts) AS day,
url,
event_id,
UNIX_SECONDS(TIMESTAMP(DATE(ts))) AS sec,
COUNT(1) AS events
FROM yourTable
GROUP BY day, url, event_id, sec
)
SELECT
url, event_id, day, events,
SUM(events)
OVER(PARTITION BY url, event_id ORDER BY sec
RANGE BETWEEN 259200 PRECEDING AND CURRENT ROW
) AS rolling3daysEvents
FROM dailyAggregations
-- ORDER BY url, event_id, day
The value of 259200 is actually 3x24x3600 so sets 3 days range, so you can set whatever actual rolling period you need