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 rep, SUM(amt) FROM Sale GROUP BY rep HAVING SUM(amt) > 250 ORDER BY rep;
- A. (Jai, 400)
- B. (Ira, 300), (Jai, 400), (Kim, 300), (Lal, 120)
- C. (Jai, 400), (Kim, 300)
- D. (Ira, 300), (Jai, 400), (Kim, 300)
Correct answer: D. (Ira, 300), (Jai, 400), (Kim, 300)
SUM ignores Ira's NULL sale, so Ira totals 100 + 200 = 300 (not NULL). Jai 400, Kim 300, Lal 120 — three groups exceed 250.
More DBMS and SQL questions
- R(A, B, C, D, E, F) has functional dependencies B → ACDEF. What is the highest normal form R satisfies?
- Which isolation anomaly is still possible at the SQL REPEATABLE READ level (as defined by the SQL standard)?
- A B-tree (not B+ tree) stores a record pointer with every key in every node. With 2048-byte blocks, 16-byte keys, 8-byte tree pointers and…
- Table P(x) rows: (1), (2), (2), (3), (NULL). Table Q(x) rows: (2), (3), (3), (NULL), (4). What does this query return? sql SELECT (SELECT…
- R(A, B) = {(1, 4), (2, 4), (3, 3), (4, 1), (4, 3)} and S(B, C) = {(1, 6), (2, 5), (2, 6), (3, 5), (4, 5)}. How many tuples are in πA(R ⋈…
- Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4…