Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Bandwidth Usage Moving Averages

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Bandwidth Usage Moving Averages. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Netflix Streaming Quality needs a subscriber-level view of bandwidth consumption. Write a PostgreSQL query that summarizes daily bandwidth usage for the requested date range and applies window functions per subscriber.

Requirements

  1. Join subscriber metadata to usage_events and include usage from April 1 through April 7, 2024.
  2. Aggregate multiple usage events on the same subscriber and date into daily_bandwidth_mb. Treat a day containing only NULL bandwidth values as zero.
  3. Calculate a three-row moving average, including the current day and up to the two preceding usage days for that subscriber.
  4. Calculate the cumulative distribution of each subscriber's daily bandwidth using CUME_DIST(), ordered from lowest to highest daily usage. Return rows ordered by subscriber and usage date.

Schema

subscribers
ColumnTypeDescription
subscriber_idPKINTUnique subscriber identifier
profile_nameVARCHAR(50)Netflix profile name
plan_tierVARCHAR(20)Subscription plan tier
usage_events
ColumnTypeDescription
usage_idPKINTUnique bandwidth event identifier
subscriber_idINTSubscriber associated with the event
usage_dateDATEDate of bandwidth usage
bandwidth_mbNUMERIC(10,2)Bandwidth consumed in megabytes
playback_surfaceVARCHAR(30)Netflix playback device or surface
Tablessubscribersusage_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results