Programming · Flashcard

Filter 2026 orders, group by customer, keep counts over 3. How?

  • AThe year in WHERE, and the order count in HAVING
  • BThe order count in WHERE, and the year in HAVING
  • CBoth in HAVING, since both narrow the final result
  • DBoth in WHERE, since both are known before grouping

Why this is the answer

Filter rows as early as possible: the year is a per-row test so it belongs in WHERE, where it also reduces how much data is grouped. The count only exists once groups are formed, so it has to be in HAVING. Getting this the wrong way round is either an error or a much slower query.

Official docs
Study in Gnoseed →