Advertisement
Georgi_Benchev

Untitled

Dec 19th, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. /* 25 Write a SQL query to find the manager who is in charge of the most employees
  2.       and their average salary.*/
  3. SELECT CONCAT(m.first_name, ' ', m.last_name) AS manager_name,
  4.        COUNT(e.employee_id)                   AS num_employees,
  5.        ROUND(AVG(m.salary))                   AS employee_avg_salary
  6. FROM employees e
  7.          JOIN employees m ON e.manager_id = m.employee_id
  8. GROUP BY e.manager_id
  9. ORDER BY num_employees DESC
  10. LIMIT 1;
  11.  
  12.  
  13. /* 26 Write a SQL query that outputs the names of the employees who have worked on the most projects.*/
  14. WITH project_counts AS (SELECT e.employee_id, e.first_name, e.last_name, COUNT(ep.project_id) AS projects_count
  15.                         FROM employees e
  16.                                  JOIN employees_projects ep ON e.employee_id = ep.employee_id
  17.                         GROUP BY e.employee_id)
  18. SELECT CONCAT(first_name, ' ', last_name) as empoloyee_name, projects_count
  19. FROM project_counts
  20. WHERE projects_count = (SELECT MAX(projects_count) FROM project_counts)
  21. ORDER BY first_name;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement