Salary Bands

MediumSQLDatabaseSorting

Description

Write a SQL query to return each employee id and a band: 'High' when salary is at least 100000, 'Mid' when at least 50000, otherwise 'Low'. Order by id ascending. **Output columns (in order):** id, band

Table:employees
ColumnType
idINT
salaryINT

Examples

Input:CREATE TABLE employees (id INT, salary INT); INSERT INTO employees VALUES (1,120000),(2,60000),(3,30000);
Output:1|High 2|Mid 3|Low
Explanation:

Each salary is mapped to a band by checking the thresholds from highest down, returned by id.

Input:CREATE TABLE employees (id INT, salary INT); INSERT INTO employees VALUES (1,50000),(2,49999),(3,100000);
Output:1|Mid 2|Low 3|High
Explanation:

Each salary is mapped to a band by checking the thresholds from highest down, returned by id.

Input:CREATE TABLE employees (id INT, salary INT); INSERT INTO employees VALUES (1,10);
Output:1|Low
Explanation:

Each salary is mapped to a band by checking the thresholds from highest down, returned by id.

Constraints

  • Use standard SQL (SQLite).

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.