Find pairs with same salary in same department
SQL
Hard
4 views
Problem Description
List employee pairs in the same department who have exactly the same salary (show both emp names).
Sample Test Case
Input:
Employees(emp_id, name, dept_id, salary)
Constraints
Self join with id ordering
Official Solution
SELECT a.dept_id, a.name AS emp1, b.name AS emp2, a.salary FROM Employees a JOIN Employees b ON a.dept_id = b.dept_id AND a.salary = b.salary AND a.emp_id < b.emp_id ORDER BY a.dept_id, a.salary;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!