Skip to content
Advertisement

write an sql query to look up the names of classes that meets in room R128

Consider the following schema:

Student(snum, sname, major,level)

Class(cname, meets-at,room, fid)

Faculty(fid, fname, depname)

Enrolled(snum, cname)

write an SQL query to find the names of all the classes that don’t meet in room R128 with the smallest number of students(compared to all other classes).

Advertisement

Answer

Try this

SELECT E.cname, Count(snum) 
    FROM Enrolled E
    GROUP BY E.cname
    HAVING Count(snum) in(
            SELECT TOP 1  Count(snum) cnameCount
            FROM Enrolled E
            JOIN Class C
            ON E.cname=C.cname
            WHERE C.room!='R128'
            GROUP BY c.CName
            ORDER BY Count(snum)
            )
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement