Skip to content

Instantly share code, notes, and snippets.

@srajangarg
Created July 26, 2016 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srajangarg/8c1e97da4f4b40787f2e9e04034bcdc2 to your computer and use it in GitHub Desktop.
Save srajangarg/8c1e97da4f4b40787f2e9e04034bcdc2 to your computer and use it in GitHub Desktop.
DB Lab 1 Discprepancies
Your Answer:
with stable as
(select course_id, sec_id, year, semester, count(ID) as numstu from takes
group by course_id, sec_id, year, semester),
enrol(max_enroll) as
(
select max(numstu) from stable
)
select course_id, sec_id, year, semester, numstu from stable, enrol
where numstu = enrol.max_enroll;
Hide Instructor Answer
Instructor's Answer:
with enrollment as
(select course_id, sec_id, year, semester, count(*) as number
from takes
group by course_id, sec_id, year, semester),
maxnumber as (
select max(number) as maxnum
from enrollment
)
select *
from enrollment, maxnumber
where number = maxnum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment