How I solved Leetcode Challenge, Employee Bonus!

Danielle Torres
2 min readMay 17, 2021

Hello Everyone,

Today I solved Leetcode challenge, Employee Bonus, using SQL. Easy challenge, but fun none the less.

Objective: Select all employee’s name and bonus whose bonus is < 1000.

Expected Output:

Tables Provided:

To start, I linked both Employee and Bonus table by their primary key (empID). Then selected fields name and bonus.

Looking at my expected output, it appeared Brad and John is returning null for their bonus. Both their empId doesn’t appear in the Bonus table because they never received a bonus.

An easy way to bring both employees into the query is to make the assumption they have zero bonus. Remember, we are bringing in employees who received a bonus less than 1000.

This is where NVL comes in to play. NVL sets any null values to a default value of your choice in this case zero. The final code will look like this:

select e.name,
b.bonus
from employee e,
bonus b
where e.empid = b.empid (+)
and nvl(b.bonus, 0) < 1000;

This passed! Please let me know what you think and if it helps you with your challenge. Until next time!

--

--

Danielle Torres

Highly organized & motivated Software Engineer with an application analyst/data analyst background.