Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Top-Performing Employee Each Month SQL
00:00
5 left

Top-Performing Employee Each Month SQL

MediumSQL · PostgreSQL

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
Interviewer

Your question is Top-Performing Employee Each Month SQL. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.