Reputation: 19
I need an average duration per week per id
SELECT ID, EXTRACT (WEEK FROM starttime) as week1, AVG(duration) OVER (PARTITION BY ID ORDER BY FORMAT_TIMESTAMP('%Y-%m-%d',starttime) ROWS BETWEEN 7 PRECEDING AND CURRENT ROW) as avgperweek FROM DB WHERE DATE(StartTime) between "2020-01-01" And "2020-10-10"
expecting to see like that
but it is ungrouping by exact day time
Upvotes: 0
Views: 593
Reputation: 173036
Below is for BigQuery Standard SQL
SELECT ID,
EXTRACT (WEEK FROM starttime) as week1,
AVG(duration) as avgperweek
FROM DB
WHERE DATE(StartTime) between "2020-01-01" And "2020-10-10"
GROUP BY ID, week1
Upvotes: 1