Management & CommerceHardBusiness analyst · SQL test

Table emp(id, name, dept, salary, mgr) has rows (1, Asha, Sales, 90, NULL), (2, Ravi, Sales, 60, 1), (3, Meena, Sales, 75, 1), (4, Kiran, Ops, 50, NULL), (5, Dev, Ops, 70, 4), (6, Neha, Ops, NULL, 4). Which employees does this return? SELECT name FROM emp e WHERE salary > (SELECT AVG(salary) FROM emp e2 WHERE e2.dept = e.dept)

  1. A. Asha and Dev
  2. B. Asha, Meena and Dev
  3. C. Asha only
  4. D. Asha, Meena, Dev and Neha

Correct answer: A. Asha and Dev

The correlated subquery computes each department's average: Sales 75, Ops 60 (NULL ignored). Asha (90 > 75) and Dev (70 > 60) qualify; Meena's 75 is not greater than 75; Neha's NULL comparison is unknown.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic