Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Ranking by Salary

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

Your question is SQL Ranking by Salary. Start with the requirements and the two 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

Intuit wants a compensation view for employees supporting TurboTax, QuickBooks, and Credit Karma. Write a PostgreSQL query that joins employee records to salary records and ranks employees by salary within each company.

Requirements

  1. Join employees to salaries using employee_id and include only employees with a non-null salary record.
  2. Assign a salary rank within each company using RANK(), with the highest salary receiving rank 1. Employees with equal salaries must share the same rank.
  3. Return the employee name, company, salary, and rank.
  4. Order the final result by company name, salary rank, and employee name.

Schema

employees
ColumnTypeDescription
employee_idPKINTEGERUnique employee identifier
employee_nameVARCHAR(100)Employee's full name
company_nameVARCHAR(50)Intuit product company or business unit
salaries
ColumnTypeDescription
salary_idPKINTEGERUnique salary record identifier
employee_idINTEGEREmployee associated with the salary record
annual_salaryNUMERIC(12,2)Annual salary amount in US dollars
Tablesemployeessalaries
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results