Show TOC

Syntax documentationSet Functions Locate this document in the navigation structure

Set functions are aggregate functions (they return one value for groups of rows and therefore imply grouping of tables).

Syntax

Syntax Syntax

  1. <set function> ::= COUNT '(' '*' ')' 
                              | COUNT '(' DISTINCT <value expression> ')'
                              | <general set function>.
    
    <general set function> ::= 
                       ( SUM | AVG | MIN | MAX ) 
                      '(' ( DISTINCT | ALL )? <value expression> ')'.
    
End of the code.

The return type of set functions follow these rules:

  • COUNT: The return type is exact numeric with scale 0.

  • AVG: The return type is approximate numeric.

  • MIN, MAX, SUM: The return type is the type of the argument.

Examples

Syntax Syntax

  1. SELECT AVG(salary) FROM employees
End of the code.

Average. This query determines the average salary of all employees.

Syntax Syntax

  1. SELECT COUNT(*) FROM employees
End of the code.

COUNT(*). This query determines the number of employees.

Syntax Syntax

  1. SELECT COUNT(DISTINCT employee_name) FROM employees
End of the code.

Average. This query determines the number of different names of the employees.

More Information

Value expressions