GATE / CS ARCHIVE

GATE CSE 2002 / QUESTION 15(b)

Degree programs with offers to over five students

Database Management Systems · SQL & Queries · Full GATE CSE 2002 paper

GATE 2002, Q15(b) Descriptive
Report issue

SQL & Queries

Question 15(b), GATE 2002: Placement schema COMPANY(cname,clocation), STUDENT(srollno,sname,sdegree), INTERVIEW(cname,srollno,idate), OFFER(cname,srollno,osalary). Keys: cname; srollno; (cname,srollno) for each remaining relation. cname and clocation are company name and location; srollno, sname and sdegree are student roll number, name and degree program. Interviews record company/student/date; offers record salary for successful interviews. Original15(b): Write SQL listing each degree program with more than five students offered jobs, together with the program name and average offered salary of its students.
Question 15(b), GATE 2002: Placement schema COMPANY(cname,clocation), STUDENT(srollno,sname,sdegree), INTERVIEW(cname,srollno,idate), OFFER(cname,srollno,osalary). Keys: cname; srollno; (cname,srollno) for each remaining relation. cname and clocation are company name and location; srollno, sname and sdegree are student roll number, name and degree program. Interviews record company/student/date; offers record salary for successful interviews. Original15(b): Write SQL listing each degree program with more than five students offered jobs, together with the program name and average offered salary of its students.
Question 15(b), GATE 2002: Placement schema COMPANY(cname,clocation), STUDENT(srollno,sname,sdegree), INTERVIEW(cname,srollno,idate), OFFER(cname,srollno,osalary). Keys: cname; srollno; (cname,srollno) for each remaining relation. cname and clocation are company name and location; srollno, sname and sdegree are student roll number, name and degree program. Interviews record company/student/date; offers record salary for successful interviews. Original15(b): Write SQL listing each degree program with more than five students offered jobs, together with the program name and average offered salary of its students.
Tap to enlarge
Answer & solution

Answer: SELECT S.sdegree, AVG(O.osalary) AS avg_offered_salary FROM STUDENT S JOIN OFFER O ON O.srollno=S.srollno GROUP BY S.sdegree HAVING COUNT(DISTINCT S.srollno)>5; (no official key was published)

A query under the usual interpretation of average offered salary, averaging the offer records, is:
SELECT S.sdegree, AVG(O.osalary) AS avg_offered_salary
FROM STUDENT AS S JOIN OFFER AS O ON O.srollno=S.srollno
GROUP BY S.sdegree
HAVING COUNT(DISTINCT S.srollno)>5;
The join associates each offer with its student's degree. COUNT(DISTINCT S.srollno) implements more than five students, not more than five offers: the composite OFFER key permits several companies to offer jobs to one student. AVG(O.osalary) averages the offered salary values within the degree group. No JOIN to INTERVIEW is needed, because OFFER already identifies successful candidates.

Original paper, page 8