Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Bandwidth Usage Moving Averages
00:00
5 left

Bandwidth Usage Moving Averages

HardSQL · PostgreSQL

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
Interviewer

Your question is Bandwidth Usage Moving Averages. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.