SQL COUNT SUM AVG

Count() Function: It returns the number of rows in selected column.

Syntax:

SELECT COUNT(column_name) FROM table_name
WHERE condition;

SAMPLE STUDENTS DATABASE:

Data
Roll_No Name Marks
1 Dev 35
2 Ayush 45
3 Ram 55
4 Pyush 65
5 Nazim 75

Example: To count the number of rows of Roll_No in students table. 

SELECT COUNT(Roll_No) FROM students;

This will result as:

Data
COUNT(Roll_No)
5

SUM() Function: It returns the total sum of selected numeric column.

Syntax:

SELECT SUM(column_name) FROM table_name
WHERE condition;

Example: To sum the marks all students in students table. 

SELECT SUM(Marks) FROM students;

This will result as:

Data
SUM(Marks)
275

AVG() Function: It returns the average of selected numeric column.

Syntax:

SELECT AVG(column_name) FROM table_name
WHERE condition;

Example: To find the average of marks all students in students table. 

SELECT AVG(Marks) FROM students;

This will result as:

Data
AVG(Marks)
55