GATE CS 2017 · Set-1 · SQL Queries

NAT · 1 mark · Problem DBMS-SQL-0079

Consider a database that has the relation schema EMP (EmpId, EmpName, DeptName). An instance of the schema EMP and a SQL query on it are given below.\[\begin{array}{|c|c|c|} \hline \text{EmpId} & \text{EmpName} & \text{DeptName} \\ \hline 1 & \text{XYA} & \text{AA} \\ 2 & \text{XYB} & \text{AA} \\ 3 & \text{XYC} & \text{AA} \\ 4 & \text{XYD} & \text{AA} \\ 5 & \text{XYE} & \text{AB} \\ 6 & \text{XYF} & \text{AB} \\ 7 & \text{XYG} & \text{AB} \\ 8 & \text{XYH} & \text{AC} \\ 9 & \text{XYI} & \text{AC} \\ 10 & \text{XYJ} & \text{AC} \\ 11 & \text{XYK} & \text{AD} \\ 12 & \text{XYL} & \text{AD} \\ 13 & \text{XYM} & \text{AE} \\ \hline \end{array}\]
SELECT AVG(EC.Num)
FROM (SELECT DeptName, COUNT(EmpId) AS Num
      FROM EMP
      GROUP BY DeptName) AS EC;
The output of executing the SQL query is

Numerical answer (NAT).

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

Show the worked solution\[\boxed{\text{AVG of the per-department counts} = \dfrac{\text{employees}}{\text{departments}}}\]The inner query gives the counts AA 4, AB 3, AC 3, AD 2, AE 1.\[\dfrac{4 + 3 + 3 + 2 + 1}{5} = \dfrac{13}{5} = 2.6\]Answer: 2.6

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