Last active
July 15, 2020 02:36
-
-
Save mzibari/65b85b8423b1999fd8ab6f35092e77e9 to your computer and use it in GitHub Desktop.
Relationship and schema design assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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