Took me a beat to realize they wanted two layers of aggregation, not just a single GROUP BY.
First, filter the server_view table to only include rows from the year 2020. Then, group by the ISO week (using a function like EXTRACT(WEEK FROM timestamp) or DATE_TRUNC('week', timestamp)) and count the total views per week. Finally, compute the average of those weekly counts using a subquery or CTE.
Pro tip: Clarify whether 'views' means distinct users or total view events; if the table has one row per view, COUNT(*) is appropriate. Also, mention that ISO weeks can span year boundaries, so filtering by year on the timestamp might exclude some weeks that partially fall in 2020—consider using ISO year instead.
Use a WHERE clause to restrict the data to timestamps within 2020. Be mindful of time zone if the timestamp is stored in UTC.
Extract the ISO week number from the timestamp (e.g., EXTRACT(WEEK FROM timestamp)) and group by that week. Alternatively, use DATE_TRUNC('week', timestamp) to get the start of each week.
For each week, count the number of views. If each row represents a view, use COUNT(*). If you need distinct users, use COUNT(DISTINCT user_id).
Wrap the grouped query in a subquery or CTE and compute the average of the weekly view counts using AVG().
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.