bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1077. Project Employees III

1077. Project Employees III

Leetcode Solutions

Using Common Table Expressions (CTEs) and MAX() Function

  1. Create a CTE named project_and_employee that joins the Project and Employee tables on the employee_id column.
  2. In the CTE, select project_id, employee_id, and experience_years.
  3. Write a subquery to select the project_id and the maximum experience_years for each project, and alias it as max_experience.
  4. In the main query, select project_id and employee_id from the CTE.
  5. Join the CTE with the subquery on project_id and where the experience_years in the CTE equals the max_experience from the subquery.
  6. Return the result of the main query.
erDiagram
    Project ||--o{ Employee : works_on
    Project {
        int project_id
        int employee_id
    }
    Employee {
        int employee_id
        varchar name
        int experience_years
    }

Using Window Functions

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...