Grouping data
A GROUP BY clause groups data by column value. For example, consider the following query:
SELECT orderNumber
FROM OrderDetails
The first 10 data rows returned by this query are as follows:
orderNumber
10100
10100
10100
10100
10101
10101
10101
10101
10102
10102
Each order number appears more than once. For example, order number 10100 appears four times. If you add a GROUP BY clause to the query, you can group the data by order number so that each order number appears only once:
SELECT orderNumber
FROM OrderDetails
GROUP BY orderNumber
The first 10 data rows returned by this query are as follows:
orderNumber
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
Typically, you use a GROUP BY clause to perform an aggregation. For example, the following query returns order numbers and order totals. The Total column is an aggregate column. An aggregate column is a computed column that uses an aggregate function such as AVG, COUNT, MAX, MIN, or SUM.
SELECT orderNumber, (SUM(quantityOrdered*priceEach)) AS Total
FROM OrderDetails
GROUP BY orderNumber
Figure 2-31 shows the first 10 data rows returned by the information object query. The data is grouped by order number and the total for each order appears.

Additional Links:

Copyright Actuate Corporation 2012