Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top-Performing Employee Each Month SQL

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

Your question is Top-Performing Employee Each Month SQL. 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

Paytm Operations needs a monthly leaderboard of employees based on completed sales processed through active Paytm channels. Write a PostgreSQL query that identifies every employee who ranked first each calendar month.

Requirements

  1. Consider only sales with sale_status = 'completed' and an active channel.
  2. Aggregate sale_amount by employee and month using the sale date.
  3. Use a ranking window function so employees tied for the highest monthly total are all returned.
  4. Return the month as YYYY-MM, employee details, and the total sales amount, ordered chronologically and then by employee ID.

Schema

employees
ColumnTypeDescription
employee_idPKINTEGERUnique employee identifier
employee_nameVARCHAR(100)Employee's full name
teamVARCHAR(100)Operations team assigned to the employee
sales
ColumnTypeDescription
sale_idPKINTEGERUnique sale identifier
employee_idINTEGEREmployee who handled the sale
channel_idINTEGERPaytm channel used for the sale
sale_dateDATEDate on which the sale was recorded
sale_amountNUMERIC(12,2)Sale amount in rupees
sale_statusVARCHAR(20)Processing status of the sale
sales_channels
ColumnTypeDescription
channel_idPKINTEGERUnique Paytm channel identifier
channel_nameVARCHAR(100)Name of the Paytm sales channel
is_activeBOOLEANWhether the channel is active
Tablesemployeessalessales_channels
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results