GateAI
SQL

GATE CSE 2021 Set 2 · Q31

MCQ2 marksEasy

Time

The relation scheme given below is used to store information about the employees of a company, where empId is the key and deptId indicates the department to which the employee is assigned. Each employee is assigned to exactly one department. emp(empId‾,name,gender,salary,deptId)\text{emp}(\underline{\text{empId}}, \text{name}, \text{gender}, \text{salary}, \text{deptId}) Consider the following SQL query:select deptId, count(*) from emp where gender = "female" and salary > (select avg(salary) from emp) group by deptId;The above query gives, for each department in the company, the number of female employees whose salary is greater than the average salary of

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: B) employees in the company.

SQL

To understand what the query computes, let us analyze its components step-by-step:

  1. Subquery Analysis: The subquery is: select avg(salary) from emp This is an uncorrelated subquery without any WHERE clause or GROUP BY clause. Therefore, it computes the overall average salary of all employees in the entire company.

  2. Outer Query Filtering (WHERE clause):where gender = "female" and salary > (select avg(salary) from emp) This filters rows from emp to retain only female employees whose salary exceeds the company-wide average salary computed by the subquery.

  3. Grouping and Aggregation (GROUP BY and SELECT):group by deptId and select deptId, count(*) The qualifying female employee tuples are grouped by deptId, and count(*) counts the number of such employees in each department.

Hence, the query outputs, for each department, the number of female employees whose salary is greater than the average salary of employees in the company.

Therefore, option (B) is correct.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This SQL previous year question is Q31 of the GATE CSE 2021 Set 2 paper. Find more GATE CSE PYQs on SQL in Databases, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related SQL PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

SQL in GATE CSE

SQL has 17 GATE CSE PYQs across 14 papers from 2011 to 2025. 5 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2021 Set 2.

How GATE tests SQL

More from GATE CSE 2021 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2021 Set 2 · Q31 · MCQ

The relation scheme given below is used to store information about the employees of a company, where empId is the key and deptId indicates the department to which the employee is assigned. Each employee is assigned to exactly one department. emp( empId, name, gender, salary, deptId) Consider the following SQL query: select deptId, count(*) from emp where gender = "female" and salary > (select avg(salary) from emp) group by deptId; The above query gives, for each department in the company, the number of female employees whose salary is greater than the average salary of

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.