Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling 30-Day Subscriber Usage Totals

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

Your question is Rolling 30-Day Subscriber Usage Totals. 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

Business Context

Bell Mobility analytics needs a daily view of subscriber data consumption to support network capacity monitoring and usage-based reporting.

Task

Write a PostgreSQL query that calculates each active Bell Mobility subscriber's rolling 30-day data usage from the recorded usage events.

Requirements

  1. Join usage events to active subscribers only.
  2. Aggregate multiple usage events for the same subscriber and date into daily_usage_mb.
  3. Use a window function partitioned by subscriber to calculate rolling_30_day_mb. The window must include the current date and the preceding 29 calendar days.
  4. Treat NULL usage values as zero and order the final output by subscriber and usage date.

Schema

bell_subscribers
ColumnTypeDescription
subscriber_idPKINTUnique Bell subscriber identifier
subscriber_nameVARCHAR(100)Subscriber display name
statusVARCHAR(20)Current subscriber account status
bell_data_usage
ColumnTypeDescription
usage_event_idPKINTUnique data usage event identifier
subscriber_idINTSubscriber associated with the usage event
usage_dateDATEDate on which usage was recorded
usage_mbNUMERIC(10,2)Data consumed in megabytes
Tablesbell_subscribersbell_data_usage
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results