The SQL Aggregate Functions are functions that provide mathematical operations. If you need to add, count or perform basic statistics, these functions will be of great help.
The functions include:
The SQL Aggregate Functions are useful when mathematical operations must be performed on all or a grouping of values.
SQL Aggregate Functions are used as follows. If a grouping of values is needed also include the GROUP BY clause.
Use a column name or expression as the parameter to the Aggregate Function. The parameter, '*', represents all rows.
SQL Aggregate Functions Syntax
SQL Aggregate Functions Example
The following example Aggregate Functions are applied to the employee_count of the branch table. The region_nbr is the level of grouping.
Here are the contents of the table:
Table: BRANCH
branch_nbr | branch_name | region_nbr | employee_count |
108 | New York | 100 | 10 |
110 | Boston | 100 | 6 |
212 | Chicago | 200 | 5 |
404 | San Diego | 400 | 6 |
415 | San Jose | 400 | 3 |
This SQL Statement with aggregate functions is executed:
Here is the result.
region_nbr | count (branch_nbr) | sum (employee_count) | min (employee_count) | max (employee_count) | avg (employee_count) |
100 | 2 | 16 | 6 | 10 | 8 |
200 | 1 | 5 | 5 | 5 | 5 |
400 | 2 | 9 | 3 | 6 | 4 |
Advertisements:
Infogoal.com is organized to help you gain mastery.
Examples may be simplified to facilitate learning.
Content is reviewed for errors but is not warranted to be 100% correct.
In order to use this site, you must read and agree to the
terms of use, privacy policy and cookie policy.
Copyright 2006-2020 by Infogoal, LLC. All Rights Reserved.