Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Employee Earnings SQL Challenge

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

Your question is Employee Earnings SQL Challenge. Start with the requirements and the one table 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

IBM's watsonx workforce analytics team needs to identify the highest potential earnings among employees. Each employee has a monthly salary and a number of months worked.

Write a PostgreSQL query that calculates each employee's total earnings as monthly_salary * months_worked, finds the highest total earnings, and counts how many employees have exactly that amount.

Requirements

  1. Use only records where monthly_salary and months_worked are not null and both values are nonnegative.
  2. Return the highest total earnings as highest_total_earnings.
  3. Return the number of employees with that exact amount as employee_count.
  4. Use a CTE or equivalent intermediate result to avoid repeating the earnings calculation.

Schema

Employee
ColumnTypeDescription
employee_idPKINTEGERUnique employee identifier
monthly_salaryNUMERIC(10,2)Employee's monthly salary
months_workedINTEGERNumber of months worked
TablesEmployee
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results