InterviewPrepKit

Home / SQL / Query Basics

Salary Bands with CASE

easy
Solving tips
  • Use a CASE expression to map a numeric range onto a label inside the SELECT list.
  • CASE evaluates WHEN branches top to bottom and stops at the first match, so order the thresholds accordingly.
  • Add an ELSE branch to catch every value not covered by the WHEN conditions.

You are given an employees table with raw salaries. Produce a readable seniority band for each person for an HR report.

Schema

CREATE TABLE employees (
  id     INTEGER PRIMARY KEY,
  name   TEXT,
  salary INTEGER
);

Sample data:

idnamesalary
1Alice45000
2Bob72000
3Carol120000
4Dave60000
5Eve95000
6Frank30000

Task

Return the name, the salary, and a computed column salary_band for each employee, ordered by id ascending. Assign the band as follows:

  • Junior when salary is less than 50000
  • Mid when salary is at least 50000 but less than 90000
  • Senior when salary is 90000 or more

Expected output

namesalarysalary_band
Alice45000Junior
Bob72000Mid
Carol120000Senior
Dave60000Mid
Eve95000Senior
Frank30000Junior
Your workspace Not runnable by design — this is your interview scratchpad. Saved on this device.