CS FundamentalsHardGATE CS · SQL
Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4, 'Dev', 'Tech', NULL, 3), (5, 'Esha', NULL, 35, 3), (6, 'Farid', 'Tech', 70, 2). How many rows of this query's result show a count of 0?
Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4, 'Dev', 'Tech', NULL, 3), (5, 'Esha', NULL, 35, 3), (6, 'Farid', 'Tech', 70, 2).
How many rows of this query's result show a count of 0?
SELECT b.name, COUNT(*) FROM Staff b LEFT JOIN Staff e ON e.boss = b.id GROUP BY b.id, b.name;
- A. 0
- B. 6
- C. 1
- D. 3
Correct answer: A. 0
COUNT(*) counts rows in each group, and an employee with no subordinates still has one LEFT-JOIN row padded with NULLs, so the minimum count is 1. COUNT(e.id) would show 0 for Dev, Esha and Farid.
More DBMS and SQL questions
- A file has 30,000 records of 120 bytes, stored unspanned in 1024-byte blocks and ordered on key K. A primary (sparse) index on K has one…
- Classify the schedule R3(B), W1(A), R3(A), W1(B), W2(B), R2(B), C2, W3(B), R1(A), C3, C1 (Ci = commit of Ti) by the strongest property it…
- An ER diagram has entity sets E1, E2, E3. R1 relates E1 and E2 many-to-many. R2 relates E2 and E3 one-to-many (each E3 entity relates to…
- Table Att(emp, day, status) rows: ('u', 1, 'P'), ('u', 2, 'P'), ('u', 3, 'A'), ('u', 4, 'P'), ('u', 5, 'P'), ('u', 6, 'P'), ('v', 1, 'A')…
- Table Product(pid, cat, price) rows: (1, 'X', 10), (2, 'X', 20), (3, 'Y', 20), (4, NULL, 30), (5, 'Y', NULL), (6, 'Z', 5). What does this…
- Classify the schedule W3(B), R2(A), R3(B), W2(A), W1(B), R1(B).