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

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.


Leave a Reply

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