CS FundamentalsHardTCS Digital · Infosys SP · GATE CS
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 rep FROM Sale s
WHERE amt = (SELECT MAX(amt) FROM Sale t
WHERE t.region = s.region)
ORDER BY rep;- A. Jai, Kim
- B. Ira, Jai, Kim
- C. Jai, Kim, Lal
- D. Kim
Correct answer: A. Jai, Kim
Per region: N's maximum is Kim's 300, S's maximum is Jai's 250 (NULL ignored). Lal's region is NULL, so t.region = NULL matches nothing, MAX is NULL and the comparison is unknown.
More DBMS and SQL questions
- 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…
- A file of 1000 blocks is sorted by external merge sort with M = 11 buffer blocks (sorted runs of M blocks are created in pass 0, then (M −…
- The system crashes after the last record of this log (immediate database modification; <Ti, X> denotes an update with old and new values…