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?
- A. 1
- B. 0
- C. 2
- 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.
Practise more Operations, Supply Chain & Business Analytics questionsOperations, Supply Chain & Business Analytics: notes and key points
More Operations, Supply Chain & Business Analytics questions
- 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…
- orders(oid, cust, amount) has rows (1, A, 100), (2, A, 200), (3, B, 300). items(oid, sku) lists the products in each order: order 1 has 2…
- Order 1 contains SKUs x and y; order 3 contains SKUs x, y and z. Query P combines the SKU lists of the two orders with UNION; query Q uses…
- Which statement about the logical order in which a SELECT query is evaluated is correct?
- Table orders has 3 rows and table items has 6 rows. How many rows does SELECT FROM orders CROSS JOIN items return?
- 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…