Interview Questions/SQL/Employee Bonus

Employee Bonus

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Description

You have two tables: Employee and Bonus. The Bonus table contains bonuses for some employees, but not all. Write a SQL query to report the name and bonus of each employee whose bonus is less than 1000. Employees with no bonus entry should also be included (treat their bonus as NULL). Return the result in any order.

Database Schema

Employee

Column NameTypeDescription
empIdINTPrimary key
nameVARCHAREmployee name
supervisorINTSupervisor's empId (nullable)
salaryINTEmployee salary

Bonus

Column NameTypeDescription
empIdINTFK to Employee, primary key
bonusINTBonus amount

Example

Employee

empIdnamesupervisorsalary
3BradNULL4000
1John31000
2Dan32000
4Thomas34000

Bonus

empIdbonus
2500
42000

Output

namebonus
BradNULL
JohnNULL
Dan500

Explanation:

Brad and John have no bonus entry (NULL < 1000 counts). Dan has bonus 500 < 1000. Thomas has bonus 2000 which is not less than 1000.

Approach hint

Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

SQL Editor
Loading...

Employee

empIdnamesupervisorsalary
3BradNULL4000
1John31000
2Dan32000
4Thomas34000

Bonus

empIdbonus
2500
42000

Output

namebonus
BradNULL
JohnNULL
Dan500