Example 1: Basic Aggregation
This example demonstrates the core concept of aggregation: grouping data based on a key.
Data: Let's say we have a table with 'OrderDate', 'CustomerID', and 'TotalAmount'."
- Grouping: By 'OrderDate'
- Aggregation: Calculate the total amount per order.
Output: TotalAmount
Example 2: Aggregating with a Date Range
Now let’s aggregate data within a specific timeframe.
Data: 'OrderDate' and 'CustomerID' data.
- Grouping: By 'OrderDate'
- Aggregation: Calculate the sum of 'TotalAmount' for each order date.
Output: SumOfTotalAmount
Example 3: Aggregating with Multiple Keys
We can aggregate multiple columns.
Data: 'OrderDate', 'CustomerID', and 'ProductCategory' column.
- Grouping: By 'OrderDate'
- Aggregation: Calculate the total 'TotalAmount' per customer and product combination.
Output: TotalAmountByCustomerProduct
Example 4: Aggregating with Customer
Aggregate by Customer. Lets say a 'Customer' column, 'CustomerID' and 'OrderDate'.
- Grouping: By 'Customer'
- Aggregation: Calculate the total order amount for each customer.
Output: TotalOrderAmount