Icon AVG

Returns the average of a given numeric, date and time, or interval expression for all selected rows.

Syntax
AVG([DISTINCT] <NumericExpression>|<DateTimeExpression>|
<IntervalExpression>)

<NumericExpression> =

Type of:

SMALLINT
INTEGER|INT
BIGINT
FLOAT
DECIMAL|NUMERIC

<IntervalExpression> =

Type of:

INTERVAL YEAR
INTERVAL YEAR TO MONTH
INTERVAL MONTH
INTERVAL DAY
INTERVAL DAY TO HOUR
INTERVAL DAY TO MINUTE
INTERVAL DAY TO SECOND
INTERVAL DAY TO MSECOND
INTERVAL HOUR
INTERVAL HOUR TO MINUTE
INTERVAL HOUR TO SECOND
INTERVAL HOUR TO MSECOND
INTERVAL MINUTE
INTERVAL MINUTE TO SECOND
INTERVAL MINUTE TO MSECOND
INTERVAL SECOND
INTERVAL SECOND TO MSECOND
INTERVAL MSECOND

Returns
Same as input

Usage
The AVG function returns the average of a given numeric, date and time, or interval expression for all selected rows. The selected rows can be grouped into logical sub-sets by using the GROUP BY clause of the SELECT statement. Any time the averaged expression is NULL, it is excluded from the average calculation.

Use the DISTINCT clause to specify that the average calculation will only use distinct values when calculating the result.

Examples
SELECT AVG(Amount) AS AvgAmount
FROM Transactions

SELECT CAST(TransDateTime AS DATE) AS TransDate,
AVG(Amount) AS AvgAmount
FROM Transactions
GROUP BY TransDate

SQL 2003 Standard Deviations
This function deviates from the SQL 2003 standard in the following ways:

DeviationDetails
None
Image