You can use an order by clause to order the results of a group by 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, the statement is:
select type, avg(price) from titles group by type order by avg(price)
type ---------- ------------ UNDECIDED NULL mod_cook 11.49 psychology 13.50 business 13.73 trad_cook 15.96 popular_comp 21.48 (6 rows affected)
Copyright © 2005. Sybase Inc. All rights reserved. |