Structured Query Language (SQL) · Class 12 · CBSE · Science Computer Science

A relation named EMPLOYEE has the columns EmpID, Dept, and Salary. Which query displays the departments whose average salary is greater than 50000?

Practice question from Structured Query Language (SQL) (Class 12 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.

hard · MCQ · Q-D2A83E

A relation named EMPLOYEE has the columns EmpID, Dept, and Salary. Which query displays the departments whose average salary is greater than 50000?

  1. A.SELECT Dept FROM EMPLOYEE WHERE AVG(Salary) > 50000 GROUP BY Dept;
  2. B.SELECT Dept FROM EMPLOYEE GROUP BY Dept HAVING AVG(Salary) > 50000;Correct answer
  3. C.SELECT Dept FROM EMPLOYEE HAVING AVG(Salary) > 50000;
  4. D.SELECT Dept, AVG(Salary) FROM EMPLOYEE WHERE Salary > 50000;

Solution

GROUP BY forms one group for each department, and HAVING filters groups based on aggregate values. Aggregate functions such as AVG() cannot normally be used in the WHERE clause for group filtering.

More from Structured Query Language (SQL)

All of Structured Query Language (SQL)

Practise more Computer Science

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed