Skip to content

Instantly share code, notes, and snippets.

@mzibari
Last active July 15, 2020 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzibari/65b85b8423b1999fd8ab6f35092e77e9 to your computer and use it in GitHub Desktop.
Save mzibari/65b85b8423b1999fd8ab6f35092e77e9 to your computer and use it in GitHub Desktop.
Relationship and schema design assignment
-- How many people work in the Sales department?
SELECT
COUNT(emp_name) AS employees_in_sales
FROM
employee
JOIN
department
ON
employee.department = department.id
WHERE
department.dept_name = 'Sales';
-- List the names of all employees assigned to the 'Plan Christmas party' project.
SELECT
emp_name
FROM
employee
JOIN
employee_project
ON
employee.id = employee_project.emp_id
JOIN
project
ON
employee_project.project_id = project.id
WHERE
project_name = 'Plan christmas party';
-- List the names of employees from the Warehouse department that are assigned to the 'Watch paint dry' project.
SELECT
emp_name
FROM
employee
JOIN
department
ON
employee.department = department.id
JOIN
employee_project
ON
employee.id = employee_project.emp_id
JOIN
project
ON
project.id = employee_project.project_id
WHERE
department.dept_name = 'Warehouse'
AND
project_name = 'Watch paint dry';
-- Which projects are the Sales department employees assigned to?
SELECT
project_name
FROM project
JOIN
employee_project
ON
project.id = employee_project.project_id
JOIN
employee
ON
employee_project.emp_id = employee.id
JOIN
department
ON
employee.department = department.id
WHERE
dept_name = 'Sales'
GROUP BY
project_name;
-- List only the managers that are assigned to the 'Watch paint dry' project
SELECT
employee.emp_name
FROM
employee
JOIN
department
ON
employee.department = department.id
JOIN
employee_project
ON
employee.id = employee_project.emp_id
JOIN
project
ON
employee_project.project_id = project.id
WHERE
department.manager = employee.id
AND
project.project_name = 'Watch paint dry';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment