Management & CommerceVery hardBusiness analyst · SQL test

Using table v, how many rows do these return? P: SELECT * FROM v WHERE amt > 60; Q: SELECT city, SUM(amt) FROM v GROUP BY city HAVING SUM(amt) > 60.

  1. A. P = 3, Q = 2
  2. B. P = 3, Q = 3
  3. C. P = 4, Q = 2
  4. D. P = 4, Q = 3

Correct answer: A. P = 3, Q = 2

P filters rows: 100, 200 and 80 exceed 60 (D's NULL does not), so 3. Q groups first: Pune 150, NULL group 280, Goa NULL; HAVING keeps Pune and the NULL group, so 2. GROUP BY treats all NULL cities as one group, and SUM over only NULLs is NULL.

More Operations, Supply Chain & Business Analytics questions

Exams that ask this topic