Skip to content

577. Employee Bonus

Problem Statement

Table: Employee

Column NameType
empIdint
namevarchar
supervisorint
salaryint

empId is the primary key column for this table.

Each row of this table indicates the name and the ID of an employee in addition to their salary and the id of their manager.

Table: Bonus

Column NameType
empIdint
bonusint

empId is the primary key column for this table.

empId has a foreign key reference to the empId column of the Employee table.

Each row of this table contains the id of an employee and their respective bonus.

Instructions

  • Write a solution to report the name and bonus amount of each employee with a bonus less than 1000.
  • Return the result table in any order.
  • The result format is in the following example.

Example

Input: Employee table

empIdnamesupervisorsalary
3Bradnull4000
1John31000
2Dan32000
4Thomas34000

Input: Bonus table

empIdbonus
2500
42000

Output:

namebonus
Bradnull
Johnnull
Dan500

Submissions

sql
SELECT
    e.name,
    b.bonus
FROM
    Employee e
LEFT JOIN
    Bonus b ON e.empId = b.empId
WHERE
    b.bonus < 1000 OR b.bonus IS NULL;

Explanations

PostgreSQL
Submitted by @noeyislearning
  • SELECT e.name, b.bonus: Select the name and bonus from the Employee and Bonus tables.
  • FROM Employee e: Select the Employee table and alias it as e.
  • LEFT JOIN Bonus b ON e.empId = b.empId: Join the Bonus table with the Employee table on the empId column.
  • WHERE b.bonus < 1000 OR b.bonus IS NULL: Filter the rows where the bonus is less than 1000 or NULL.