UGC-NET Jun 2015 · SQL Queries

MCQ · 2 marks · Problem DBMS-SQL-0019

The STUDENT information in a university stored in the relation STUDENT (Name, SEX, Marks, DEPT_Name). COnsider the following SQL Query:
SELECT DEPT_Name from STUDENT where SEX='M'
group by DEPT_Name having avg(Marks)>SELECT avg(Marks) from STUDENT
It returns the name of the department for which
  1. A
    The average marks of Male students is more than the average marks of students in the department
  2. B
    The average marks of Male students is more than the average marks of students in the university
  3. C
    The average marks of students is more than the average marks of male students in the university
  4. D
    The average marks of Male students is more than the average marks of male students in the university

Solve it on GATE DA practice →More Relational Model & SQL problems

Show the worked solutionWHERE SEX = 'M' keeps only male students. GROUP BY DEPT\_Name with HAVING avg(Marks) then compares each department's male average with the subquery, which is the average marks of all students in the university (no filters). So the query returns the departments where the average marks of male students exceed the university average.(A) The comparison is not with the department's own average — incorrect.(C) reverses the comparison — incorrect.(D) The subquery has no male filter — incorrect.Answer: B

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com