Export (0) Print
Expand All

GROUP BY and the WHERE Clause

SQL Server 2000

GROUP BY and the WHERE Clause

You can use a WHERE clause in a query containing a GROUP BY clause. Rows not meeting the conditions in the WHERE clause are eliminated before any grouping is done. For example:

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

Here is the result set:

type                                    
------------ -------------------------- 
business     2.99                       
mod_cook     2.99                       
popular_comp 21.48                      
psychology   14.30                      
trad_cook    17.97                      

(5 row(s) affected)

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

See Also

SELECT

WHERE

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft