GATE / CS ARCHIVE

GATE CSE 1994 / QUESTION 13(b)

SQL grouped aggregation

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

GATE 1994, Q13(b) Descriptive
Report issue

SQL & Queries

Question 13(b), GATE 1994: COURSES(cno,cname), primary key cno; STUDENTS(rollno,sname,age,year), primary key rollno; REGISTERED_FOR(cno,rollno), composite primary key (cno,rollno). year denotes the student’s current year of study. Write SQL to print the age and year of the youngest student in each year.
Question 13(b), GATE 1994: COURSES(cno,cname), primary key cno; STUDENTS(rollno,sname,age,year), primary key rollno; REGISTERED_FOR(cno,rollno), composite primary key (cno,rollno). year denotes the student’s current year of study. Write SQL to print the age and year of the youngest student in each year.
Tap to enlarge
Answer & solution

Answer: SELECT MIN(age) AS age, year FROM STUDENTS GROUP BY year; (no official key was published)

1. Group rows by year so each year is processed independently.

2. MIN(age) computes the youngest age within that group. Output just age and year, as requested, rather than an arbitrary student name or roll number.

3. Ties need no extra rows because the requested attributes are identical for tied youngest students. Standard SQL ignores NULL ages; if all ages in a year are NULL, the result is NULL.

Original paper, page 6