Accessing Data : Accessing database data using the query builder : Specifying the data to retrieve : Grouping data
 
Grouping data
If you use aggregate functions, such SUM or AVG, you typically have to group the results by one or more columns. For example, an Orders table contains order records and some customers have multiple orders. To get the order totals for each customer, you would use the GROUP BY clause to group the customers, and the SUM function to aggregate the order totals by customer.
How to group data
1 Choose Groups.
2 Under Column, click in an empty row. Click the arrow button, and select the column whose aggregate data to group. Figure 4‑22 shows an example in which results are grouped on the CUSTOMERNAME column.
Figure 4‑22 Grouping on the CUSTOMERNAME column
The following GROUP BY clause is added to the SELECT statement:
GROUP BY CLASSICMODELS.CUSTOMERS.CUSTOMERNAME