GATE / CS ARCHIVE

GATE CSE 2016 SET 2 / QUESTION 52

GATE CSE 2016 Set 2 Q52

Database Management Systems · SQL & Queries · Full GATE CSE 2016 Set 2 paper

GATE 2016 Set 2, Q52 2 marks · NAT
Report issue

SQL & Queries

Question 52, GATE 2016: water_schemes(scheme_no,district_name,capacity) rows: (1,Ajmer,20),(1,Bikaner,10),(2,Bikaner,10),(3,Bikaner,20),(1,Churu,10),(2,Churu,20),(1,Dungargarh,10). Printed pseudocode: with total(name,capacity) as select district_name,sum(capacity) from water_schemes group by district_name; with total_avg(capacity) as select avg(capacity) from total; select name from total,total_avg where total.capacity≥total_avg.capacity. How many output tuples under the intended CTE interpretation? The printed text repeats WITH and omits required CTE parentheses.
Tap to enlarge
Answer & solution

Official answer: 2.0 : 2.0

Our answer: 2 under intended corrected CTE syntax

Per-district totals are Ajmer20, Bikaner40, Churu30, Dungargarh10; their mean is 25. Bikaner and Churu meet the >=25 condition, so the intended result has 2 tuples. Literal standard SQL requires parenthesized CTE bodies and a comma separating total and total_avg under one WITH clause. The printed repeated WITH and missing parentheses are not executable standard CTE syntax; the official 2 assumes those syntax repairs.

GROUP BY first produces one row per district, so AVG operates over four totals, not the seven original scheme rows. The single average row is crossed with those four totals; filtering retains 40 and 30. A repaired standard SQL form uses WITH total AS (...), total_avg AS (...) SELECT ..., making the intended semantics executable without claiming the printed syntax is valid.

Original paper, page 42 · Answer key