Skip to content
GATEiit

GATE CSE 2017 Session 1 Q33: SQL: average of per-department employee counts

Syllabus topic: Relational model: relational algebra, tuple calculus and SQL

Question

Consider a database that has the relation schema EMP (EmpId, EmpName, and DeptName). An instance of the schema EMP and a SQL query on it are given below.

EMP
EmpIdEmpNameDeptName
1XYAAA
2XYBAA
3XYCAA
4XYDAA
5XYEAB
6XYFAB
7XYGAB
8XYHAC
9XYIAC
10XYJAC
11XYKAD
12XYLAD
13XYMAE
SELECT AVG(EC.Num)
FROM EC
WHERE (DeptName, Num) IN
      (SELECT DeptName, COUNT(EmpId) AS
                        EC(DeptName, Num)
       FROM EMP
       GROUP BY DeptName)

The output of executing the SQL query is ________.

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 2.6 (official GATE 2017 final answer key)

Concept used: GROUP BY with COUNT gives one row per department; AVG then averages those counts.

Concept notes

Loading notes…

First step: Count employees in each department (AA, AB, AC, AD, AE) to form EC, then average the Num column.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Relational model: relational algebra, tuple calculus and SQL

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2017 Session 1 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key