CS FundamentalsHardGATE CS (PYQ pattern)

SALE(r, q, amt): (n,1,10), (n,2,30), (s,1,5), (s,2,5), (s,3,5), (e,1,50). View V is SELECT r, SUM(amt) AS tot, COUNT(*) AS c FROM SALE GROUP BY r. What does SELECT SUM(tot) FROM V WHERE c >= 2 return, and what does SELECT AVG(tot) FROM V return?

  1. A. 55 and 35
  2. B. 105 and 35
  3. C. 55 and 17.5
  4. D. 55 and 45

Correct answer: A. 55 and 35

V has three rows: n = (40, 2), s = (15, 3), e = (50, 1). Rows with c >= 2 are n and s: 40 + 15 = 55. AVG over the view's three rows is 105 / 3 = 35, not the average over the six SALE rows (17.5).

More DBMS and SQL questions

Exams that ask this topic