Consider the following schema: Emp (Empcode, Name, Sex, Salary, Deptt) A…

2015

Consider the following schema:

Emp (Empcode, Name, Sex, Salary, Deptt)

A simple SQL query is executed as follows:

SELECT Deptt FROM Emp
WHERE sex = 'M'
GROUP by Dept
Having avg (Salary) > {select avg (Salary) from Emp}

The output will be

  1. A.

    Average salary of male employee is the average salary of the organization

  2. B.

    Average salary of male employee is less than the average salary of the organization

  3. C.

    Average salary of male employee is equal to the average salary of the organization

  4. D.

    Average salary of male employee is more than the average salary of the organization

Attempted by 244 students.

Show answer & explanation

Correct answer: D

The SQL query begins by filtering the Emp table to include only male employees using WHERE sex = 'M'.

Next, the filtered rows are grouped by department using GROUP BY Deptt.

A subquery calculates the average salary for all employees in the entire table.

The HAVING clause compares the average salary of males in each department against this overall organization average.

Finally, the query returns the department names where the average male salary is greater than the global average.

Explore the full course: Isro