SQL – Count(), Avg() and Sum() Function


SQL – Count(), Avg() and Sum() Function

Table Of Contents:

  1. What Is Count(), Avg() and Sum() Function?
  2. Syntax Of Count(), Avg() and Sum() Function.
  3. Examples Of Count(), Avg() and Sum() Function.

(1) What Is Count(), Avg() and Sum() Function?

  • The COUNT() function returns the number of rows that matches a specified criterion.
  • The AVG() function returns the average value of a numeric column.
  • The SUM() function returns the total sum of a numeric column

(2) Syntax Of Count(), Avg() and Sum() Function?

Syntax: Count()

SELECT COUNT(column_name)
FROM table_name
WHERE condition;

Syntax: Avg()

SELECT AVG(column_name)
FROM table_name
WHERE condition;

Syntax: Sum()

SELECT SUM(column_name)
FROM table_name
WHERE condition;

(3) Exampls Of Count(), Avg() and Sum() Function?

Demo Data:

Example-1:Count()

SELECT COUNT(ProductName)
FROM Products;

Example-2:Avg()

SELECT AVG(Price)
FROM Products;

Example-3:Sum()

SELECT SUM(Price)
FROM Products;

Leave a Reply

Your email address will not be published. Required fields are marked *