GATE / CS ARCHIVE

GATE CSE 2001 / QUESTION 21(b)

Query above-average examinees

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

GATE 2001, Q21(b) Descriptive
Report issue

SQL & Queries

Question 21(b), GATE 2001: examinee(regno,name,score), where regno is a primary key and score is real. List registration numbers with score above the relation-wide average.
Question 21(b), GATE 2001: examinee(regno,name,score), where regno is a primary key and score is real. List registration numbers with score above the relation-wide average.
Tap to enlarge
Answer & solution

Answer: SELECT regno FROM examinee WHERE score > (SELECT AVG(score) FROM examinee); (no official key was published)

Use an uncorrelated scalar subquery to compute one average over all examinees:

SELECT e.regno
FROM examinee AS e
WHERE e.score > (SELECT AVG(x.score) FROM examinee AS x);

The outer query compares each score with the same global average. Strict > excludes scores exactly equal to that average. No GROUP BY is needed because the intended comparison is to the whole relation, not a separate average per person or centre. The primary key ensures no duplicate registration number in the result. In SQL, AVG ignores NULL scores and comparison with NULL is unknown, so NULL-score rows do not qualify; the stated mathematical real-number model normally excludes this extra case.

Original paper, page 10