0% found this document useful (0 votes)
0 views

Multiple Tables

СЉЛ

Uploaded by

sofija_779737984
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Multiple Tables

СЉЛ

Uploaded by

sofija_779737984
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Working with Multiple Tables

1. Write a query to list pairs of students who are enrolled in the same course.
Include their IDs and the course title.

SELECT Person.PersonID, Course.Title AS CourseTitle


FROM Person
JOIN StudentGrade ON Person.PersonID = StudentGrade.StudentID
JOIN Course ON StudentGrade.CourseID = Course.CourseID
WHERE HireDate IS NULL
ORDER BY CourseTitle ASC

2. Write a query to find the total number of students enrolled in each


department, along with the department name. Include only departments with
at least one student enrolled. Hint: search little bit about HAVING reserved
word in SQL and use it here.
SELECT Department.Name AS DepartmentName, COUNT(PersonID) AS
#StudentsPerDepartment
FROM Department
JOIN Course ON Department.DepartmentID = Course.DepartmentID
JOIN StudentGrade ON Course.CourseID = StudentGrade.CourseID
JOIN Person ON StudentGrade.StudentID = Person.PersonID
WHERE HireDate IS NULL
GROUP BY Department.Name
HAVING COUNT(PersonID) > 1 OR COUNT(PersonID) = 1

3. Find the average grade for each department. Include departments with no
students and set the average grade to NULL if no grades are available.
???

You might also like