COUNT AVG SUM in SQL

HOW TO USE COUNT() AVG() SUM() FUNTIONS IN SQL?

COUNT() function returns the number of rows that matches a specified condition.

Syntax โ€“

SELECT  COUNT(ColumnName)

FROM <TableName>

WHERE<condition> ;   

Example-

SELECT  Count(ProductID)

FROM Products;

AVG() function returns the average value of a numeric column.

Syntax โ€“

SELECT  AVG(ColumnName)

FROM <TableName>

WHERE<condition> ;

Example-

SELECT  AVG(Price)

FROM Products;

SUM() function returns the sum value of a numeric column.

Syntax โ€“

SELECT  SUM(ColumnName)

FROM <TableName>

WHERE<condition> ;

Example-

SELECT  SUM(Quantity)

FROM OrderDetails;

Note-

Northwind sample database is used for examples.


Posted

in

Tags:

Comments

Leave a Reply