Similar Problems

Similar Problems not available

Employees With Missing Information - Leetcode Solution

Companies:

LeetCode:  Employees With Missing Information Leetcode Solution

Difficulty: Easy

Topics: database  

The problem "Employees With Missing Information" on LeetCode asks you to find all the employees within a given company who have missing information. There are two tables: Employee (which contains data for all employees) and Employee_Salary (which contains the salaries of each employee).

To solve this problem, firstly, we need to understand the problem's requirements and constraints clearly, and then we can approach it in several ways.

  1. Understanding the Problem

We have been given two tables, Employee and Employee_Salary, where Employee has the following attributes:

id | name | department | manager_id | hire_date | salary ---|------|------------|------------|-----------|------- 1 | Joe | IT | 3 | 2020-01-01| 50000 2 | Bob | Sales | 1 | 2019-01-01| 60000 3 | Tom | IT | null | 2018-01-01| 45000 4 | Jane | HR | 2 | 2017-01-01| 55000

And Employee_Salary table has the following attributes:

id | salary ---|------- 1 | 20000 2 | 30000 3 | null 4 | 25000

Here, we need to find out all the employees who have missing information either in their salary or manager_id.

  1. Approach

We can approach this problem using a LEFT JOIN on the two tables and then filter out the employees who have null values for salary or manager_id.

The query for this would look something like this:

SELECT Employee.id, Employee.name, Employee.department
FROM Employee 
LEFT JOIN Employee_Salary 
ON Employee.id=Employee_Salary.id
WHERE Employee.salary IS NULL OR Employee.manager_id IS NULL; 

This query will return all the employees who have missing data in either their salary or manager_id in the Employee table.

  1. Testing

Let's test the above solution by running the query on the given tables.

SELECT Employee.id, Employee.name, Employee.department
FROM Employee 
LEFT JOIN Employee_Salary 
ON Employee.id=Employee_Salary.id
WHERE Employee.salary IS NULL OR Employee.manager_id IS NULL; 

This query will return the following output:

id | name | department ---|------|------------ 3 | Tom | IT

As we can see from the output, only one employee, Tom, has missing data in either salary or manager_id. Therefore, the solution has passed the test and is correct.

  1. Conclusion

In conclusion, we can solve the problem "Employees With Missing Information" on LeetCode by using a LEFT JOIN to combine the two tables and then filter out the employees who have missing data in either their salary or manager_id.

Employees With Missing Information Solution Code

1