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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Rolling 7-Day Usage SQL
00:00
5 left

Rolling 7-Day Usage SQL

MediumSQL · PostgreSQL

Problem

Verizon's network analytics team wants to monitor short-term data consumption trends for active subscribers. Write a PostgreSQL query that calculates a rolling 7-day average of daily data usage for each active subscriber.

Requirements

  1. Aggregate multiple usage records from the same subscriber and date into one daily total.
  2. Return one row per active subscriber and usage date, including the daily total in megabytes.
  3. Calculate the average over the current date and the six preceding calendar days using a window function. Missing dates should not be treated as zero usage.
  4. Sort the output by subscriber ID and usage date.

Schema

subscriber_accounts
ColumnTypeDescription
subscriber_idPKINTUnique Verizon subscriber identifier
subscriber_nameVARCHAR(100)Subscriber display name
statusVARCHAR(20)Current account status
subscriber_usage
ColumnTypeDescription
usage_idPKINTUnique usage event identifier
subscriber_idINTSubscriber associated with the usage event
usage_dateDATEDate of mobile data usage
data_usage_mbNUMERIC(12,2)Data consumed in megabytes
Tablessubscriber_accountssubscriber_usage
Interviewer

Your question is Rolling 7-Day Usage SQL. 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.