Once the groups exist you may want to filter them as well: "the genres whose average price is above 80". That condition cannot be asked of a single row, because the average only exists once the group is built. WHERE filters rows; `HAVING` filters groups.
SELECT genre, AVG(price) AS averageFROM booksWHERE year >= 2000GROUP BY genreHAVING COUNT(*) >= 3ORDER BY average DESC;
WHERE drops the books from before 2000, GROUP BY sorts the rest into genres, HAVING drops the genres with fewer than three books, ORDER BY sorts the result. WHERE runs before the grouping, HAVING after.Totalling by a period of time is the same pattern: group by the month column, add the amount up with SUM, sort by month. A large share of all reports is those three lines.