SQL

How To Use Aggregate Functions In SQL

In this article, we will learn how to use the Aggregate Functions in SQL.

An Aggregate Function allows us to perform a calculation on a set of values to return a single scalar value. We often use aggregate functions with the GROUP BY and HAVING clauses of the SELECT statement.

Below is a selection from the “tblEmployees” table:

SELECT * FROM tblEmployees ORDER BY Salary DESC;

The following are the most commonly used SQL Aggregate Functions.

Function Description
AVG() It returns the average value of an expression.
SELECT AVG(Salary) AS AverageSalary FROM tblEmployees;

Output: 19210

COUNT() It returns the number of records returned by a select query.
SELECT COUNT(ID) AS NoOfEmployees FROM tblEmployees;

Output: 5

MAX() It returns the maximum value in a set of values.
SELECT MAX(Salary) AS HighestSalary FROM tblEmployees;

Output: 30000

MIN() It returns the minimum value in a set of values.
SELECT MIN(Salary) AS SmallestSalary FROM tblEmployees;

Output: 10000

SUM() It calculates the sum of a set of values.
SELECT SUM(Salary) AS TotalSalary FROM tblEmployees;

Output: 96050

 

Also, check How To Get Second Highest Salary Using Query In SQL

Yasin Panwala

Yasin Panwala is a Web Developer and Author at TheCodeHubs. He has experience in Web Developing and Designing and also in Writing. He has got his skills in working on technologies like .NET Core, ADO.NET, AJAX, Angular, AngularJS, ASP.NET, ASP.NET MVC, Bootstrap, C#, CSS, Entity Framework, Express.js, GraphQL, HTML, JavaScript, JQuery, JSON, LINQ, Microsoft Office, MongoDB, MySQL, Node.js, PostgreSQL, SQL, SQL Server, TypeORM, TypeScript, Visual Basic .NET, Web API. He also got his skills in working with different integration and some known versioning tools. He is always ready to learn new things and he always tries his best on tasks that are assigned to him and gives the best possible outputs.

View Comments

  • I know this if off topic but I'm looking into starting my own blog and was curious what all is required to get setup? I'm assuming having a blog like yours would cost a pretty penny? I'm not very web smart so I'm not 100 positive. Any recommendations or advice would be greatly appreciated. Thank you

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago