Aggregate Functions
Aggregate Functions
Aggregate Functions: These functions are also known as Multiple Row Functions or Group
Functions.
These functions operate on a set of rows to return a single value. These functions are:
Aggregate (Group) Functions :
Points to remember
In Count function , when the argument is a column name or an expression based on a column ,
count() returns the number of non – NULL values in that column.
If the argument is a *, then count() returns the total number of rows in a table, including
duplicates and nulls.
e.g. Assume table SHOES contains 13 rows then the query
SELECT COUNT(*) FROM SHOES; gives output as 13 indicating that there are 13 records in
the SHOES table. Whereas the query SELECT COUNT(MARGIN) FROM SHOES where
MARGIN is a column gives output as 10 indicating that there are 10 values in the MARGIN
column of SHOES table and remaining(3) are NULL values.
Also SELECT COUNT(DISTINCT CITY) FROM MEMBERS : Here distinct is used to count
the number of distinct cities in CITY column whereas SELECT COUNT(ALL CITY) FROM
MEMBERS : Here all is used to count the entries including repeats ignoring NULL values.
All other aggregate functions such as sum, max,min,avg ignores NULL values of a
column.