Grouping Records

The GROUP BY clause is used to produce a 'subtotal only' report, where one line is printed for each group, for example:

SELECT order_number
FROM order_line
GROUP BY order_number;

groups together the orders and prints each order number once. You can use the column functions to calculate values such as group totals and averages.