Define aggregate queries during SQL Data Selection
Define Aggregate Queries during SQL Data Selection
An aggregate query is one that contains a specific
Transact-SQL function that performs a calculation on a set of values.
This calculation is returned by the query as a single value. For example, if you wanted to know how much you are paying out in salaries, you could ask for the total of all values in the Salary column in the Employees table.
Aggregates are used in conjunction with the GROUP BY clause.
There are ten aggregate functions within the Transact-SQL language. They are:
AVG Returns the average of all values in a group of values
COUNT Returns the number of rows in the table(s) for which the criteria applies in a group of values
GROUPING Used with On-line Analytical Processing (OLAP) functionality.
MAX Returns the maximum value in a group of values
MIN Returns the minimum value in a group of values
SUM Returns the summarization, or addition, of all values in a group of values
STDEV Returns the statistical standard deviation
STDEVP Returns the statistical standard deviation for a population of values
VAR Returns the statistical standard variance
VARP Returns the statistical standard variance for a population of values
There are a couple of attributes to remember about these functions. Each of the functions ignore null values, except for the COUNT function. Also, each of the functions uses the following syntax:
In the next lesson, you will learn how to use aggregate functions in your queries.
Aggregate: A query or part of a query that performs mathematical summing on one or more columns.