Skip to main contentSkip to solution

Which query correctly finds a category in the 'Commodity' table that has more than 5 products with a Price greater than 600?

Solution

✅ Correct Option: 2

WHERE filters individual rows before grouping, so WHERE Price>600 keeps only products costing more than 600. GROUP BY category then groups those rows, and HAVING COUNT(*)>5 keeps only categories with more than 5 such products.


Option 1: Price is not grouped or aggregated, so it cannot be used in HAVING. The row-level condition belongs in WHERE.

Option 3: it makes the same mistake of putting Price>600 in HAVING, and it also returns an extra COUNT column that was not asked for.

Option 4: GROUP BY has no column named, so it is a syntax error. Also, COUNT(Price>600) counts every non-NULL result of the comparison, including false ones, so it does not count only the products above 600.

Use WHERE for conditions on individual rows and HAVING for conditions on aggregates such as COUNT, SUM or AVG.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question