| < PREVIOUS | NEXT > |
SUM, AVG and COUNT FUNTIONS
- The SUM() function returns the total sum of a numeric column.
- The AVG() function returns the average value of a numeric column.
- The COUNT() function returns the number of rows that matches a specified criterion.
SUM(), AVG() and COUNT() SYNTAX
SELECT SUM(column_name)
FROM table_name
WHERE condition;
SELECT AVG(column_name)
FROM table_name
WHERE condition;
SELECT COUNT(column_name)
FROM table_name
WHERE condition;
EXAMPLES
Suppose there is a Table name as “HrEmployee” having Age, Attrition, BusinessTravel, DailyRate, Department, DistanceFromHome, Education, EducationField columns, EmployeeNumber, etc as Columns.
- SQL statement finds the sum of the “DailyRate” fields in the “HrEmployee” table:
SELECT SUM(DailyRate) FROM HrEmployee;
During the sum, Null values are ignored
- SQL statement finds the average of the “DailyRate” fields in the “HrEmployee” table:
SELECT AVG(DailyRate) FROM HrEmployee;
- SQL statement finds the number of Female worker from “HrEmployee”:
SELECT COUNT(GENDER) FROM HrEmployee Where GENDER = "FEMALE"
| < PREVIOUS | NEXT > |