CS FundamentalsHardProduct-company MCQ pattern

Table Emp(id, name, dept, salary, mgr) rows: (1, 'Asha', 'HR', 50000, NULL), (2, 'Ravi', 'IT', 70000, 1), (3, 'Meena', 'IT', 70000, 2), (4, 'John', 'Sales', 40000, 1), (5, 'Kiran', 'IT', 90000, 2), (6, 'Dev', NULL, 45000, 4), (7, 'Lata', 'Sales', NULL, 4). Which employees are returned?

Table Emp(id, name, dept, salary, mgr) rows: (1, 'Asha', 'HR', 50000, NULL), (2, 'Ravi', 'IT', 70000, 1), (3, 'Meena', 'IT', 70000, 2), (4, 'John', 'Sales', 40000, 1), (5, 'Kiran', 'IT', 90000, 2), (6, 'Dev', NULL, 45000, 4), (7, 'Lata', 'Sales', NULL, 4). Which employees are returned?
SELECT name FROM Emp e
WHERE salary > (SELECT AVG(salary) FROM Emp x
                WHERE x.dept = e.dept);
  1. A. Kiran, Ravi and Meena
  2. B. Kiran and Asha
  3. C. Kiran and Dev
  4. D. Kiran only

Correct answer: D. Kiran only

Department averages: HR 50000, IT ≈ 76667, Sales 40000 (NULL ignored). Only Kiran (90000) beats his average; Asha and John equal theirs. For Dev, x.dept = NULL matches no row, the average is NULL, and the comparison is UNKNOWN.

More DBMS and SQL questions

Exams that ask this topic