ASA SQL User's Guide
Summarizing, Grouping and Sorting Query Results
The ORDER BY clause: sorting query results
You can use an ORDER BY clause to order the results of a GROUP BY in a particular way.
The following query finds the average price of each product and orders the results by average price:
SELECT name, AVG(unit_price) FROM product GROUP BY name ORDER BY AVG(unit_price)
| name | AVG(product.unit_price) |
|---|---|
| Visor | 7 |
| Baseball Cap | 9.5 |
| Tee Shirt | 12.333333333 |
| Shorts | 15 |
| ... | ... |