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 region IS NOT NULL
GROUP BY rep
HAVING COUNT(DISTINCT region) =
(SELECT COUNT(DISTINCT region) FROM Sale)
ORDER BY rep;- A. Jai
- B. Ira, Jai, Kim
- C. Ira, Jai
- D. No rows (empty result)
Correct answer: C. Ira, Jai
COUNT(DISTINCT region) over the table ignores NULL, so it is 2 (N and S). Ira and Jai have sold in both regions; Kim only in N. This is division with GROUP BY/HAVING.
More DBMS and SQL questions
- R(A, B) = {(a1, b2), (a1, b3), (a2, b2), (a2, b3), (a3, b1), (a3, b3), (a4, b1), (a4, b2), (a4, b3)} and S(B) = {b1, b2}. What is R ÷ S?
- Classify the schedule R3(A), R3(B), W1(A), R1(A), C3, R2(A), C1, W2(B), W2(A), C2 (Ci = commit of Ti) by the strongest property it…
- Consider the schedule W1(A), R1(B), W2(A), R1(A), R3(B), W3(A), R2(A). Which statement is correct?
- In multiple-granularity locking, transaction T1 holds an SIX lock on a table. Which lock request by another transaction on the same table…
- On R(A, B, C, D, E), F = {D → C, C → AB, E → BC} and G = {BE → AC, CD → B, BD → C}. Which statement is correct? ("F covers G" means every…
- Keys 7, 31, 43, 34, 16, 26, 39, 38, 29, 44 are inserted in this order into an empty B+ tree where a node holds at most 3 keys; an…