Aggregate Functions

Aggregate functions perform an operation on a group of values taken from a series of records. For example, the AVG function computes the average of a field’s value over the selected records. The following statement calculates the average Score value for records with StudentId value 1001:

SELECT AVG(Score) 
FROM Scores 
WHERE StudentId = 1001 

Table A.3 describes aggregate functions available in SQL Server.

Table A.3. Useful Aggregate Functions
Function Purpose
AVG Calculates the average of the selected values.
COUNT Returns the number of selected records.
MAX Returns the largest value selected.
MIN Returns the smallest value selected.
SUM Returns the sum of the selected values.
STDEV Calculates the statistical standard deviation ...

Get Visual Basic® .NET Database Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.