This Tutorial will teach you how to use Aggregate Functions in SQL Queries.

Introduction

This Tutorial will teach you about all of the basic Aggregate functions in SQL. These functions can be used to perform mathematical equations to SQL columns and allow you to pull this Data out of the table.

Step 1. List of the Aggregate Functions
1. AVG() – Returns the average value
2. COUNT() – Returns the number of rows
3. FIRST() – Returns the first value
4. LAST() – Returns the last value
5. MAX() – Returns the largest value
6. MIN() – Returns the smallest value
7. SUM() – Returns the sum of all rows

All of these functions can be used in correspondence with the GROUP BY Function from our previous tutorial (here) in order to dive into the full functionality of the GROUP BY Function

Step 2. Basic Uses of the Aggregate Functions

The following SQL Queries are examples of how these Functions can be used.
1. In a SELECT Statement Grabbing the Sum of a Column

This command will add up all of the numbers in a column and return them

2.Using the AS statement to name the returned value

when trying to use any of the numbers created it is always best to use the AS function. The AS function names the number that is returned so that you can uses it when you like.

3. In a Where Clause Grabbing the Above average Customers

This Function will grab the Customers whose OrderPrices are greater than the Average number of OrderPrices. Notice the second SELECT Command is perfectly legal, this allows you to chain SELECT Commands to narrow down your results.

Conclusion

In this Tutorial we learned all about Aggregate Functions and how they can be used to simplify Mathematical equations on Table columns. We also learned about their possible placements in SQL Queries and where they can be useful.