Aggregate functions
Aggregate functions return a single value from a set of records. You can use an aggregate function as part of a SELECT
statement, with a field name (for example, AVG(SALARY)
), or in combination with a column expression (for example, AVG(SALARY * 1.07)
).
You can precede the column expression with the DISTINCT
operator to eliminate duplicate values.
COUNT (DISTINCT last_name)
In this example, only unique last name values are counted.
Aggregate function |
Returns |
|
The total of the values in a numeric field expression. For example, |
|
The average of the values in a numeric field expression. For example, |
|
The number of values in any field expression. For example, |
|
The maximum value in any field expression. For example, |
|
The minimum value in any field expression. For example, |
SELECT SUM (Sales_Data.Amount) AS agg FROM Sales_Data
SELECT AVG (Sales_Data.Amount) AS agg FROM Sales_Data
SELECT COUNT (Sales_Data.Amount) AS agg FROM Sales_Data
SELECT MAX (Sales_Data.Amount) AS agg FROM Sales_Data WHERE Sales_Data.Amount < 3000
SELECT MIN (Sales_Data.Amount) AS agg FROM Sales_Data WHERE Sales_Data.Amount > 3000
You cannot use an aggregate function as an argument to other functions. If you do, FileMaker software returns the error code 8309 ("Expressions involving aggregations are not supported"). For example, the following statement is not valid because the aggregate function SUM
cannot be used as an argument to the function ROUND
:
SELECT ROUND(SUM(Salary), 0) FROM Payroll
However, aggregate functions can use functions that return numbers as arguments. The following statement is valid.
SELECT SUM(ROUND(Salary, 0)) FROM Payroll