Decode Analytics

View Original

Select Count, AVG, SUM

The COUNT() function returns the number of rows.

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

The SUM() function returns the total sum of a column.


SQL Select COUNT() Syntax:

SELECT COUNT(Column1)

FROM Table_Name

WHERE condition;

SQL Select AVG() Syntax:

SELECT AVG(Column1)

FROM Table_Name

WHERE condition;

SQL Select SUM() Syntax:

SELECT SUM(Column1)

FROM Table_Name

WHERE condition;


Example:

Lets use the following table to count the number of Products from the SupplierName column with the name of ‘TechOne’.

See this content in the original post


Results:

See this content in the original post

Now lets find the average price of Products from the SupplierName column with the name of ‘TechOne’.

SELECT AVG(Price) as Result

FROM Products

WHERE SupplierName = ‘TechOne’

See this content in the original post


Results:

See this content in the original post

Finally lets find the sum price of Products from the SupplierName column with the name of ‘TechOne’.

See this content in the original post

Results:

See this content in the original post

SQL Tutorial

See this content in the original post