Skip to content

Instantly share code, notes, and snippets.

@JALsnipe
Created March 6, 2014 03:10
Show Gist options
  • Save JALsnipe/2f87631cac253afe536b to your computer and use it in GitHub Desktop.
Save JALsnipe/2f87631cac253afe536b to your computer and use it in GitHub Desktop.
SELECT s.sid, s.sname, m.dname, s.gpa, e.dname, e.cno, e.grade
FROM student s, enroll e, major m
WHERE s.sid = e.sid AND s.sid = m.sid AND
(SELECT AVG(e1.grade)
FROM enroll e1
WHERE s.sid = e1.sid AND e1.dname in (
SELECT m1.dname
FROM major m1
WHERE s.sid = m1.sid)) <
(SELECT AVG(e2.grade)
FROM enroll e2
WHERE s.sid = e2.sid AND e2.dname NOT IN (
SELECT m2.dname
FROM major m2
WHERE s.sid = m2.sid))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment