CS FundamentalsModerateAmazon/Flipkart SQL round · 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 COUNT(*) FROM Sale s1 JOIN Sale s2 ON s1.rep = s2.rep AND s1.id < s2.id;
- A. 8
- B. 4
- C. 3
- D. 5
Correct answer: B. 4
Pairs of different sales by the same rep: Ira has 3 sales → C(3,2) = 3 pairs, Jai has 2 → 1 pair, Kim and Lal have one each. Total 4.
More DBMS and SQL questions
- Which statement about ARIES recovery is correct?
- Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4…
- R(A, B, C, D, E, F) has functional dependencies F → ABCD, BD → A. What is the highest normal form R satisfies?
- Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4…
- Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4…
- TS(T1) = 20, TS(T2) = 5, TS(T3) = 25; all read/write timestamps start at 0. Under basic timestamp ordering with Thomas's write rule, which…