GROUP BY and ORDER BY

Add an ORDER BY clause to a SELECT statement when you want the results to be ordered in a particular way. Put the ORDER BY clause after the GROUP BY clause.

For example, to find the average price of each type of book and order the results by average price, type:

SELECT type, AVG(price)
FROM titles
GROUP BY type
ORDER BY AVG(price)



type


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

UNDECIDED
(null)

mod_cook
11.49

psychology
15.96

business
15.97

trad_cook
21.48

popular_comp
41.06




(6 row(s) affected)