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 does this query return?
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 does this query return?
SELECT dept, MAX(pay) - MIN(pay) FROM Staff GROUP BY dept HAVING COUNT(pay) = COUNT(*);
- A. 3
- B. 2
- C. 0
- D. 1
Correct answer: B. 2
GROUP BY makes three groups: Ops, Tech and NULL (Esha). Tech fails HAVING because Dev's pay is NULL (COUNT(pay) = 2 ≠ 3). Ops and the NULL group both pass, so 2 rows.
More DBMS and SQL questions
- Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4…
- Consider the schedule W2(A), R1(A), R2(A), W3(A), R3(A), R1(C). Which statement is correct?
- TS(T1) = 25, TS(T2) = 5, TS(T3) = 30; all read/write timestamps start at 0. Under basic timestamp ordering (no Thomas write rule), which…
- R(A, B, C, D, E) has functional dependencies DE → B, C → E, D → AC. What is the highest normal form R satisfies?
- R(A, B, C, D, E, F) has functional dependencies C → B, F → C, DF → B, B → F, A → F. What is the closure {AE}⁺?
- R(A, B, C, D, E) with functional dependencies B → E, CE → B, C → E, E → C is decomposed into R1(A, C, E), R2(A, B, D), R3(B, C). Which…