CS FundamentalsModerateGATE CS · SQL
Table Sale(id, rep, region, amt) rows: (1, 'Ira', 'N', 100), (2, 'Jai', 'S', 250), (3, 'Ira', 'S', NULL), (4, 'Kim', 'N', 300), (5, 'Jai', 'N', 150), (6, 'Ira', 'N', 200), (7, 'Lal', NULL, 120). What does this query return?
Table Sale(id, rep, region, amt) rows: (1, 'Ira', 'N', 100), (2, 'Jai', 'S', 250), (3, 'Ira', 'S', NULL), (4, 'Kim', 'N', 300), (5, 'Jai', 'N', 150), (6, 'Ira', 'N', 200), (7, 'Lal', NULL, 120).
What does this query return?
SELECT COUNT(*) FROM (SELECT DISTINCT rep, region FROM Sale);
- A. 5
- B. 3
- C. 6
- D. 2
Correct answer: C. 6
DISTINCT applies to the (rep, region) pair: (Ira, N), (Jai, S), (Ira, S), (Kim, N), (Jai, N), (Lal, NULL). Only Ira's two N sales collapse: 7 − 1 = 6. DISTINCT keeps the NULL pair (5 would be COUNT(DISTINCT rep, region), which skips it); 3 and 2 come from looking at region alone.
More DBMS and SQL questions
- Keys 47, 46, 27, 42, 22, 7, 58, 45, 48, 51 are inserted in this order into an empty B+ tree where a node holds at most 3 keys; an…
- Table Sale(id, rep, region, amt) rows: (1, 'Ira', 'N', 100), (2, 'Jai', 'S', 250), (3, 'Ira', 'S', NULL), (4, 'Kim', 'N', 300), (5, 'Jai'…
- R(A, B) = {(5, 2), (8, 1), (8, 2), (11, 1), (14, 2)}. What does πA(R) − π{R1.A}(σ{R1.A < R2.A}(ρ{R1}(R) × ρ{R2}(R))) return?
- Assertion (A): A schedule can be conflict serializable and still not be recoverable. Reason (R): Serializability concerns the order of…
- How many of these statements about two-phase locking are correct? 1. Basic 2PL guarantees conflict serializability. 2. Basic 2PL prevents…
- Table Route(src, dst, cost) rows: ('A', 'B', 5), ('B', 'C', 4), ('A', 'C', 12), ('C', 'D', 3), ('B', 'D', 9), ('D', 'A', 2). What does…