Medium Writes & indexes Premium

SQL interview question: UPDATE With CASE

Tiered Annual Bonus

Annual bonuses are tiered by role: VPs get $10,000, anyone with 'Manager' in their title gets $5,000, and everyone else gets $2,000.

Write a single UPDATE statement adding the right bonus to every employee's salary using CASE.

Note: Check VP titles first - some managers report to VPs, but a 'VP Sales' is not a 'Manager'. Your change is verified automatically and rolled back afterwards.

This challenge changes data. Your statement runs on a private copy of the database, then we check the resulting table.

Tables

employees 37 rows
  • id integer PK
  • first_name text
  • last_name text
  • email text
  • department_id integer → departments
  • salary integer
  • hire_date text
  • manager_id integer → employees
  • title text
idfirst_namelast_nameemaildepartment_idsalaryhire_datemanager_idtitle
1AliceChen[email protected]12500002015-01-15NULLCEO
2RobertMartinez[email protected]21800002016-03-20NULLCEO
3SarahJohnson[email protected]11500002017-06-101VP Engineering

Keep going