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). How many employees earn more than their own manager, as found by SELECT COUNT(*) FROM emp e JOIN emp m ON e.mgr = m.id WHERE e.salary > m.salary?

  1. A. 1
  2. B. 0
  3. C. 2
  4. D. 3

Correct answer: A. 1

The self-join pairs each employee with his manager: Ravi 60 vs Asha 90, Meena 75 vs Asha 90, Dev 70 vs Kiran 50, Neha NULL vs Kiran 50. Only Dev earns more, so the count is 1; Neha's NULL comparison is unknown and is dropped.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic