Leetcode Problem 1875. Group Employees of the Same Salary

1875. Group Employees of the Same Salary

Leetcode Solutions

Using DENSE_RANK() and Subquery to Filter Unique Salaries

  1. Create a subquery to select salaries that are shared by more than one employee using GROUP BY and HAVING COUNT(*) > 1.
  2. Use the DENSE_RANK() window function to assign a rank to each salary, which will serve as the team_id.
  3. Filter the main query to include only those employees whose salaries are in the list obtained from the subquery.
  4. Order the final result by team_id and employee_id in ascending order.

erDiagram
    Employees {
        int employee_id
        varchar name
        int salary
    }

Using COUNT() OVER and Subquery to Exclude Unique Salaries

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...