Closed
Conversation
Implement a function to retrieve the Nth highest salary from the Employee table.
Create function to get Nth highest salary
Add SQL query for second highest salary
|
🧙 Sourcery has finished reviewing your pull request! Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Title Format: 181.EmployeesEarningMoreThanTheirManagers.cpp
🧠 Intuition
The problem requires identifying employees who earn more than their managers.
Each record in the Employee table contains id, name, salary, and managerId.
By comparing an employee’s salary with their manager’s salary, we can find those whose salary exceeds that of their manager.
💡 Approach
Self Join:
We perform a self join on the Employee table — one instance (e1) represents the employee, and the other (e2) represents the manager.
Join Condition:
We join both tables where the employee’s managerId matches the manager’s id.
Filter Condition:
We then use a WHERE clause to filter only those employees whose salary is greater than their manager’s salary.
Select Output:
Finally, we select the employee’s name as the output column Employee.
✅ Code Solution (C++ / SQL)
SELECT e1.name AS Employee
FROM Employee e1
JOIN Employee e2 ON e1.managerId = e2.id
WHERE e1.salary > e2.salary;
🔗 Related Issues
Closes #181
By submitting this PR, I confirm that:
This is my original work not totally AI generated
I have tested the solution thoroughly on LeetCode
I have maintained proper PR description format
This is a meaningful contribution, not spa
Summary by Sourcery
Scaffold directories for LeetCode SQL problems 176 and 177 and add the Employees Earning More Than Their Managers (#181) SQL solution
New Features: