Logo

K-Learn

SQL COUNT, AVG, SUM Aggregate Functions

< Previous Next >

SQL COUNT, AVG, and SUM are aggregate functions used to perform calculations on a set of values in a column.

COUNT()

The COUNT function is used to count the number of rows in a table or the number of non- values in a column.

COUNT() Syntax

SELECT COUNT(column_name)
FROM table_name
WHERE condition;

For example,

SELECT COUNT(*) FROM student;

OUTPUT

In this example,

This SQL statement returns the number of rows in the "student" table.

AVG()

The AVG function is used to calculate the average of the values in a column. 

AVG() Syntax

SELECT AVG(column_name)
FROM table_name
WHERE condition;

For example,

SELECT AVG(marks) FROM exam;

OUTPUT

In this above Example,

This SQL statement returns the average of the "marks" column in the "exam" table.

SUM()

The SUM function is used to calculate the sum of the values in a column.

SUM() Syntax

SELECT SUM(column_name)
FROM table_name
WHERE condition;

For example,

SELECT SUM(marks) FROM exam;

OUTPUT

In this above Example,

This SQL statement returns the total sum of the "marks" column in the "exam" table.


< Previous Next >