Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Query for 3rd Largest

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

Your question is SQL Query for 3rd Largest. Start with the requirements and the four 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

The Airtel Thanks analytics team wants to identify subscribers with the third-highest total mobile data consumption for January 2026. Write a PostgreSQL query that aggregates usage for active subscribers and ranks distinct usage totals.

Requirements

  1. Join subscribers, active subscriptions, Airtel plans, and usage sessions.
  2. Sum each active subscriber's January 2026 data usage in MB, treating subscribers with no usage as zero.
  3. Return every subscriber tied at the third-highest distinct usage total. Use a window function rather than LIMIT and OFFSET.
  4. Return customer_id, customer_name, plan_name, and total_data_mb, ordered by customer_id.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique Airtel subscriber identifier
customer_nameVARCHAR(100)Subscriber display name
account_statusVARCHAR(20)Current account state
subscriptions
ColumnTypeDescription
subscription_idPKINTUnique subscription identifier
customer_idINTReferences customers.customer_id
plan_idINTReferences plans.plan_id
subscription_statusVARCHAR(20)Current subscription state
plans
ColumnTypeDescription
plan_idPKINTUnique Airtel plan identifier
plan_nameVARCHAR(100)Commercial name of the Airtel plan
usage_sessions
ColumnTypeDescription
session_idPKINTUnique data usage session identifier
customer_idINTReferences customers.customer_id
data_mbINTData consumed during the session in MB
usage_dateDATEDate on which the data was consumed
usage_typeVARCHAR(30)Network usage classification
Tablescustomerssubscriptionsplansusage_sessions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results