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

  • Home
  • SQL
  • SQL COUNT(), AVG() and SUM()

COUNT()


It returns number of rows after matching some conditions.

Syntax COUNT()


SELECT COUNT(column_name) FROM table_name
WHERE condition;



AVG()


It returns average value of numeric column.

Syntax AVG()


SELECT AVG(column_name) FROM table_name
WHERE condition;



SUM()


It returns sum of numeric column.

Syntax SUM()


SELECT SUM(column_name) FROM table_name
WHERE condition;



ProductID ProductName ProductPrice
12 Syrup 20
13 Coffee 15
14 Chips 18
15 Juice 22


COUNT() Example




SELECT COUNT(ProductID) FROM Product;



COUNT(ProductID)
4


AVG() Example




SELECT AVG(ProductPrice) FROM Product;



AVG(ProductPrice)
18.75


SUM() Example




SELECT SUM(ProductPrice) FROM Product;



SUM(ProductPrice)
75

Back To Top