Skip to content

Instantly share code, notes, and snippets.

@JALsnipe
Created March 6, 2014 04:04
Show Gist options
  • Save JALsnipe/44575dc33fcbbb950dcf to your computer and use it in GitHub Desktop.
Save JALsnipe/44575dc33fcbbb950dcf to your computer and use it in GitHub Desktop.
SELECT cno, dname, b.count_of_students
FROM
(SELECT COUNT(*) AS num_of_students
FROM student s, enroll e
WHERE s.sid = e.sid) a,
(
SELECT c.cno, c.dname, COUNT(*) as count_of_students
FROM course c RIGHT OUTER JOIN enroll e
ON c.cno = e.cno
WHERE c.cno = e.cno AND c.dname = e.dname
GROUP BY c.cno, c.dname) b
WHERE b.count_of_students < 0.08 * a.num_of_students
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment