Question
For a given quarter, the table Student lists all students registered at the University, the table Course lists all courses offered, and the table Enrollment
For a given quarter, the table Student lists all students registered at the University, the table Course lists all courses offered, and the table Enrollment encodes the students that attend any course in the current quarter.
Student (Sid, Sname)
Course (Cid, Cname)
Enrollment (Cid,Sid)
primary key is Student (Sid),Course(Cid),Enrollment(Cid,Sid)
Note: a primary key is underlined and a foreign key is italic.
1. A classmate of a student is another student who is enrolled in at least one same class. Write a SQL query that returns all students with all of their classmates. You should return their student IDs, as their names do not uniquely identify them. (5 points)
2. Write a SQL query that computes for each student id in the Student table the total number of different classmates that this student has across all courses. Note that a student may be so busy with research (or parties :-)) that he or she may choose not to enroll to any course that quarter, and hence has no classmates. Such students should still appear in the result, with 0 as the number of their classmates. (5 points)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started