Notes
Notes - notes.io |
SELECT project_name, SUM(hours_per_week)
FROM project
JOIN project_assignment
ON project.project_id = project_assignment.project_number
GROUP BY project_name
Sometimes, the database can have not have the same name for the keys
SELECT p.project_name, SUM(pa.hours_per_week)
FROM project AS p
JOIN project_assignment AS pa
ON p.project_id = pa.project_number
GROUP BY p.project_name
SELECT project_name, SUM(hours_per_week)
FROM project, project_assignment
WHERE project.project_id = project_assignment.project_number
GROUP BY project_name
(the JOIN condition is specified in the WHERE clause. 2 tables in the FROM clause matches them all up
Question 29: Show the name of each project and the name of the department that manages the project
SELECT p.project_name, d.department_name
FROM project AS p
JOIN department AS d
ON p.departmentid = d.departmentid
SELECT p.project_name, d.department_name
FROM project AS p
JOIN department AS d
USING(departmentid)
Using assumes that the two tables to be joined have a column that is the exact same name
Question 30: Show the names of all employees, the projects they work on and the number of hours per week they work on each project.
SELECT e.first_name, e.last_name, p.project_name, pa.hours_per_week
FROM employee AS e
JOIN project_assignment AS pa
ON e.employeeid = pa.employeeid
JOIN project AS p
ON p.project_id = pa.project_number
Question 31: Show the names of all employees, the projects they work on and the number of hours per week they work on each project, and the name of the department that manages the project
SELECT e.first_name, e.last_name, p.project_name, pa.hours_per_week, d.department_name
FROM employee AS e
JOIN project_assignment AS pa
ON e.employeeid = pa.employeeid
JOIN project AS p
ON p.project_id = pa.project_number
JOIN department AS d
ON e.departmentid = d.departmentid
Question 32: Show the names of all of the departments and the employees that work in each department
SELECT d.department_name, e.first_name, e.last_name
FROM department AS d
JOIN employee AS e
ON d.departmentid = e.departmentid
However, this query does not show the Shipping Department
Use a LEFT JOIN (show all of the records to the table to the left, department)
Show all of the records in the department table
SELECT d.department_name, e.first_name, e.last_name
FROM department AS d
LEFT JOIN employee AS e
ON d.departmentid = e.departmentid
Question 33: Which departments have no employees?
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team