SQL
COUNT(), AVG() and SUM() Function

COUNT() Function

COUNT function return number of rows base on given criteria.

Syntax


    SELECT COUNT(column_name)
    FROM table_name
    WHERE condition;

Example

This example will return you the number of records in student table.


    SELECT COUNT(studentId)
    FROM student;

AVG() Function

AVG function returns average value of a numeric column.

Syntax


    SELECT AVG(column_name)
    FROM table_name
    WHERE condition;

Example

This query will returns you the average fee of the students from student table.


    SELECT AVG(Fee)
    FROM student;

SUM() Function

SUM function returns total sum a numeric column.

Syntax


    SELECT SUM(column_name)
    FROM table_name
    WHERE condition;

Example

This query will returns you the total fee of the students from student table.


    SELECT SUM(Fee)
    FROM student;