Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Joins and Aggregates

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

Your question is SQL Joins and Aggregates. Start with the requirements and the three 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

AT&T Wireless needs a monthly usage report for active subscribers. Write a PostgreSQL query that reports each active subscriber's May 2025 mobile data usage, including subscribers with no usage events.

Requirements

  1. Join subscribers to plans and retain only rows where status = 'active'.
  2. Aggregate data_mb and usage-event count from usage_records for May 2025 only.
  3. Use a LEFT JOIN and COALESCE so active subscribers without usage appear with zero totals.
  4. Sort by total data usage descending, then subscriber ID ascending.

Schema

subscribers
ColumnTypeDescription
subscriber_idPKINTUnique subscriber identifier
subscriber_nameVARCHAR(100)Subscriber's name
plan_idINTSubscribed wireless plan
statusVARCHAR(20)Current account status
plans
ColumnTypeDescription
plan_idPKINTUnique plan identifier
plan_nameVARCHAR(100)AT&T wireless plan name
usage_records
ColumnTypeDescription
usage_idPKINTUnique usage event identifier
subscriber_idINTSubscriber associated with the event
usage_dateDATEDate of the usage event
data_mbINTMobile data consumed in megabytes
Tablessubscribersplansusage_records
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results