SQL Flow Field Guide

AVG

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

aggregation

What changes

Input
the argument expression over each group's rows (COUNT(*) reads no column)
Output or change
one value per group (or one for the whole input when there is no GROUP BY)
Return type
The evaluated result of expression determines the return type. Expression result Return type tinyint int smallint int int int bigint bigint decimal category (p, s) decimal(38, max(s,6)) money and smal

Syntax at a glance

AVG ( [ ALL | DISTINCT ] expression ) [ OVER ( [ partition_by_clause ] order_by_clause ) ]

Work example

Find an average per team, month, or other reporting group.

Compare the average with the row count and decide how the displayed scale should round.

Check your work AVG ignores null inputs and its return type follows the input type rules.

Practice SQL

Open in SQL Flow
SELECT AVG(CAST(score AS decimal(9,2))) AS mean_score FROM (VALUES (70), (80), (NULL)) AS v(score);

Open Microsoft Learn for full syntax, permissions, and details for your version.