GATE CS 2021 Set 2 | Question 41

Databases › SQL Queries · MCQ · 2 marks · Answer: B

  1. Question 41Databasesmcq2 marks
    The relation scheme stores employee information, where empId is the key and deptId is the department to which the employee is assigned. Each employee is assigned to exactly one department.
    emp(empId, name, gender, salary, deptId)
    Consider the 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:
    • A.
      employees in the department.
    • B.
      employees in the company.
      ✓
    • C.
      female employees in the department.
    • D.
      female employees in the company.

    Answer: B

    Solution

    The subquery (select avg(salary) from emp) is uncorrelated and computes the average salary over all employees in the company, so the comparison is against the company-wide average.

More GATE PYQ on SQL Queries

All GATE CS Databases PYQ →

Attempt GATE CS 2021 Set 2 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →