Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling 7-Day Usage SQL

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

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

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results