GROUP BY and the WHERE Clause

You can use a WHERE clause in a query containing a GROUP BY clause. Rows that don't satisfy the conditions in the WHERE clause are eliminated before any grouping is done. Here's an example:

SELECT type, AVG(price)
FROM titles
WHERE advance > $5000
GROUP BY type



type


------------
-------

business
11.96

mod_cook
2.99

popular_comp
21.48

psychology
24.80

trad_cook
17.97




(5 row(s) affected)


Only rows with advances greater than $5000 are included in the groups shown in the query results.