(40 points) Q2. Consider the following relations: Student(sid: integer, sname: s
ID: 3596344 • Letter: #
Question
(40 points) Q2. Consider the following relations: Student(sid: integer, sname: string, major: string, level: string, age: integer) Class(name: string, meets at: string, room: string, fid: integer) Enrolled(sid: integer, cname: string) Faculty(fid: integer, fname: string, deptid: integer) The meaning of these relations is straightforward; for example, Enrolled has one record per student-class pair such that the student is enrolled in the class. Write the following queries in SQL. No duplicates should be printed in any of the answers. 1. Find the age of the youngest student who is enrolled in a course taught by I. Teach. 2. Find the names of all classes that have ten or more students enrolled. 3. Find the names of all classes that either meet in room R128 or have ten or more students enrolled. . For all levels except JR, print the level and the maximum age of students for that level. 5.1 Find the names of students not enrolled in any class.Explanation / Answer
1. select min(age) from Student s , Enrolled e , Faculty f , Class c where s.sid = e.sid and e.cname = c.name and c.fid = f.fid and f,fname = 'I. Teach';
2. select distinct(cname) from Enrolled group by cname having count(*) >=10;
3. select distinct(name) from Class where room = 'R128'
union
select distinct(cname) from Enrolled group by cname having count(*) >=10;
4. select level, max(age) from Student where level != 'JR' group by level;
5. select sname from Student
minus
select sname from Student s, Enrolled e where s.sid = e.sid;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.