DATABASE USING MY SQL
Multiple Row Functions (Aggregate
Function)
Aggregate functions summarize the results
of a query and return a single value
calculated from values in a column instead
of providing the listing of all of the rows.
Syntax:
SELECT <FUNCION> (column name)
FROM <table_name>; The following are
aggregate functions:
1) SUM(): returns the total sum of a numeric
column. It gives the arithmetic sum of all the
values present in a particular column. It can take
only one argument. NULL values are not included
in the calculations. Example: SELECT
SUM(MARKS) FROM STUDENT;
It displays sum of all the marks in the table student
2) AVG (): returns the average value of any
column or expression based on a column. NULL
value not included (average=add the item/no of
item)
Example: SELECT AVG(MARKS) FROM STUDENT;
It displays average of all the marks in the table student
3) MAX (): It returns the maximum value among
the given set of values of any column or
expression based on column.
Example: SELECT MAX(MARKS) FROM STUDENT;
It displays maximum marks from the column marks of
student table.
4) MIN(): It returns the minimum value among
the given set of values of any column or
expression based on column.
Example: SELECT MIN (MARKS) FROM STUDENT;
It displays minimum marks from the column marks of
student table.
(for alphabets min and max is calculated based on asci
code A-Z(65-90) and a-z(97-122))
5) COUNT(): It count the number of non-null
values in a column. It can take one argument,
which can be a column name or *. When the
argument is a column name then COUNT() returns
the non-null values in that column. If the
argument is an * then COUNT() counts the total
number of records / rows along with the NULL
values satisfying the condition, if any, in the table.
So, it returns the total number of records or rows
from the table.
Syntax: SELECT COUNT(COLUMN_NAME) FROM
<TABLE_NAME>;
Count(*)-It counts all the values in the column
including null value
Example: SELECT COUNT(*) FROM STUDENT ;
It will give output as 10 rows.
But while writing SELECT COUNT(MARKS) FROM
STUDENT;
Will give output as 7 because there will be 3 null
values which is ignored by COUNT()