Subqueries & CTEs · Question 10 · Medium

Subqueries & CTEs question 10

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

What does this query return?

WITH dept_total AS (
  SELECT dept, SUM(salary) AS total
  FROM Faculty
  GROUP BY dept
)
SELECT dept
FROM dept_total
WHERE total > 100000
ORDER BY dept;
  1. CSE
  2. CSE; ECE
  3. CSE; ECE; MECH
  4. CSE; CSE
Answer and explanation

Answer: B. CSE; ECE

Explanation: The CTE gives one row per department: CSE 315000, ECE 150000, MECH 60000. The main query filters these totals, so CSE and ECE qualify. Filtering single salaries above 100000 would be a different question.

Previous: Table Faculty: fid | name | dept | salary 1 | Anand | CSE | 90000 2 | Bhavna |… · 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