Subqueries & CTEs · Question 9 · Medium

Subqueries & CTEs question 9

Table Faculty:
fid | name | dept | salary
1 | Anand | CSE | 90000
2 | Bhavna | CSE | 120000
3 | Charu | ECE | 75000
4 | Dhruv | ECE | 75000
5 | Esha | MECH | 60000
6 | Firoz | CSE | 105000

Which names does this query return?

SELECT name
FROM Faculty f
WHERE salary > (SELECT AVG(salary)
                FROM Faculty g
                WHERE g.dept = f.dept)
ORDER BY name;
  1. Bhavna
  2. Bhavna; Firoz
  3. Anand; Bhavna; Firoz
  4. Anand; Bhavna; Charu; Dhruv; Firoz
Answer and explanation

Answer: A. Bhavna

Explanation: Each salary is compared with the average of that person's own department: CSE 105000, ECE 75000, MECH 60000. Only Bhavna (120000) is strictly above her department's average; Firoz, Charu, Dhruv and Esha are exactly equal to theirs.

Previous: Table Members: mid | name 1 | Geeta 2 | Hari 3 | Imran 4 | Jaya Table Loans… · Next: Table Faculty: fid | name | dept | salary 1 | Anand | CSE | 90000 2 | Bhavna |…

Practise subqueries & ctes

Try a fresh set of subqueries & ctes questions with an explanation after every answer, free and without signing up: Subqueries & CTEs practice. Or sit a full placement mock test.

More subqueries & ctes questions

More sql practice

Window Functions · NULL Handling · SQL Functions & CASE · UNION, INTERSECT & EXCEPT · Tables, Keys & Constraints · DML & Transactions · SELECT, WHERE & ORDER BY · SQL Joins

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge