Aggregate functions are typically used in arithmetic expressions. Aggregate functions operate on a group of rows and return a single numeric value in the result table for each group.
In the following statement, the SUM aggregate function operates on the group of rows defined by the Sales_Table table:
SELECT SUM(Total_Sales) FROM Sales_Table;
Sum(Total_Sales) ---------------- 5192.40
You can use GROUP BY clauses to produce more complex, finer grained results in multiple result values. In the following statement, the SUM aggregate function operates on groups of rows defined by the Product_ID column in the Sales_Table table:
SELECT Product_ID, SUM(Total_Sales) FROM Sales_Table GROUP BY Product_ID;
Product_ID Sum(Total_Sales) ---------- ---------------- 101 2100.00 107 1000.40 102 2092.00
For information on:
- Window aggregate functions and their Teradata-specific equivalents, see Window Aggregate Functions.
- Aggregate user-defined functions (UDFs), see Aggregate UDF.
- Window aggregate UDFs, see Window Aggregate UDF.
Topics:
- Aggregates in the Select List
- Aggregates and GROUP BY
- Aggregates and Date
- Aggregates and Literal Expressions in the Select List
- Nesting Aggregates
- Results of Aggregation on Zero Rows
- Aggregates and Nulls
- Aggregate Operations on Floating Point Data
- Aggregates and LOBs
- Aggregates and Period Data Types
- Aggregates and SELECT AND CONSUME Statements
- Aggregates and Recursive Queries
- Aggregates in WHERE and HAVING Clauses
- DISTINCT Option
- Aggregates and Row Level Security Tables
- Time Series Aggregate Functions Overview
- Aggregate Functions Related Information