Interview Query

Weighted Average With Missing Dates

Start Timer

0:00:00

Upvote
5
Downvote
Save question
Mark as completed
View comments (8)
Next question

The analytics team at a social media platform wants to analyze the short-term trends in daily user growth. For this task, they want you to calculate the 3-day rolling weighted average for new daily users, where the current day has a weight of 3, the previous day has a weight of 2, and the day before has a weight of 1.

The platform logs new records into the acquisitions table for the days on which new users arrive. Otherwise, it skips the date.

Write a SQL query to calculate the 3-day rolling weighted average for new daily users from the acquisitions table.

Round the average to two decimal places.

Example:

Input:

acquisitions table

Column Type
date DATE
new_users DECIMAL

Output:

Column Type
date DATE
weighted_average DECIMAL
.
.
.
.
.


Comments

Loading comments