6/3/22, 2:53 PM SQL Aggregate Functions: SUM(), COUNT(), AVG(), Functions
Software Development
Articles Ebooks Video Tutorials Live Webinars On-demand Webinars Free Practice Tests
Home Resources Software Development SQL Aggregate Functions: SUM(), COUNT(), AVG(), Functions
SQL Aggregate Functions: SUM(), COUNT(), AVG(), Functions
By Aryan Gupta
Last updated on Sep 27, 2021 47841
Table of Contents
What is an Aggregate Function in SQL?
COUNT() Function
SUM() Function
AVG() Function
MIN() Function
https://www.simplilearn.com/tutorials/sql-tutorial/sql-aggregate-functions#:~:text=An aggregate function in SQL performs a calculation on multiple,exc… 1/12
6/3/22, 2:53 PM SQL Aggregate Functions: SUM(), COUNT(), AVG(), Functions
View More
Software Development
An aggregate
Articles function
Ebooks in SQL
Video performs
Tutorials Livea Webinars
calculation On-demand
on multipleWebinars
values andFree
returns a single
Practice Testsvalue.
SQL provides many aggregate functions that include avg, count, sum, min, max, etc. An aggregate
function ignores NULL values when it performs the calculation, except for the count function.
What is an Aggregate Function in SQL?
An aggregate function in SQL returns one value after calculating multiple values of a column. We
often use aggregate functions with the GROUP BY and HAVING clauses of the SELECT statement.
Various types of SQL aggregate functions are:
Count()
Sum()
Avg()
Min()
Max()
Business Analyst Master's Program
Gain expertise in Business analytics tools
EXPLORE PROGRAM
COUNT() Function
The COUNT() function returns the number of rows in a database table.
https://www.simplilearn.com/tutorials/sql-tutorial/sql-aggregate-functions#:~:text=An aggregate function in SQL performs a calculation on multiple,exc… 2/12
6/3/22, 2:53 PM SQL Aggregate Functions: SUM(), COUNT(), AVG(), Functions
Software Development
Syntax:
Articles Ebooks Video Tutorials Live Webinars On-demand Webinars Free Practice Tests
COUNT(*)
or
COUNT( [ALL|DISTINCT] expression )
Example:
We will use the ‘products’ table from the sample database for our demonstration.
The following SQL statement fetches the number of products in the table.
This will produce the following result.
The below-given command will display those product ids where the unit price is greater than 4.
https://www.simplilearn.com/tutorials/sql-tutorial/sql-aggregate-functions#:~:text=An aggregate function in SQL performs a calculation on multiple,exc… 3/12
6/3/22, 2:53 PM SQL Aggregate Functions: SUM(), COUNT(), AVG(), Functions
This will display the following result.
Software Development
Articles Ebooks Video Tutorials Live Webinars On-demand Webinars Free Practice Tests
Let's look at how we can use GROUP BY and HAVING functions with the COUNT function.
Consider the following dataset:
The SQL command given below will list the number of customers in each city.
This will produce the following results:
https://www.simplilearn.com/tutorials/sql-tutorial/sql-aggregate-functions#:~:text=An aggregate function in SQL performs a calculation on multiple,exc… 4/12
6/3/22, 2:53 PM SQL Aggregate Functions: SUM(), COUNT(), AVG(), Functions
Software Development
FREE Course: Introduction to Data Analytics
Articles Ebooks Video Tutorials Live Webinars On-demand Webinars Free Practice Tests
Mastery to Data Analytics Basics is a Click Away!
START LEARNING
SUM() Function
The SUM() function returns the total sum of a numeric column.
Syntax:
SUM()
or
SUM( [ALL|DISTINCT] expression )
Example:
The following SQL statement finds the sum of the "unit price" fields in the "products" table:
This will produce the following result.
Let’s look at how we can use GROUP BY and HAVING functions with the SUM function.
Consider the following dataset:
https://www.simplilearn.com/tutorials/sql-tutorial/sql-aggregate-functions#:~:text=An aggregate function in SQL performs a calculation on multiple,exc… 5/12
6/3/22, 2:53 PM SQL Aggregate Functions: SUM(), COUNT(), AVG(), Functions
Software Development
Articles Ebooks Video Tutorials Live Webinars On-demand Webinars Free Practice Tests
The SQL command below will list the number of customers in each city, having a sum of points
greater than 3000.
This will produce the following result:
AVG() Function
The AVG() function calculates the average of a set of values.
Syntax:
AVG()
or
AVG( [ALL|DISTINCT] expression )
https://www.simplilearn.com/tutorials/sql-tutorial/sql-aggregate-functions#:~:text=An aggregate function in SQL performs a calculation on multiple,exc… 6/12
6/3/22, 2:53 PM SQL Aggregate Functions: SUM(), COUNT(), AVG(), Functions
Software Development
Example:
Articles Ebooks Video Tutorials Live Webinars On-demand Webinars Free Practice Tests
The following SQL command calculates the average quantity in stock.
This will produce the following result.
MIN() Function
The MIN() aggregate function returns the lowest value (minimum) in a set of non-NULL values.
Syntax:
MIN()
or
MIN( [ALL|DISTINCT] expression )
Example:
The above code will give us the minimum quantity in stock in the products table.
https://www.simplilearn.com/tutorials/sql-tutorial/sql-aggregate-functions#:~:text=An aggregate function in SQL performs a calculation on multiple,exc… 7/12
6/3/22, 2:53 PM SQL Aggregate Functions: SUM(), COUNT(), AVG(), Functions
Software Development
MAX() Function
Articles Ebooks Video Tutorials Live Webinars On-demand Webinars Free Practice Tests
The MAX() aggregate function returns the highest value (maximum) in a set of non-NULL values.
Syntax:
AVG()
or
AVG( [ALL|DISTINCT] expression )
Example:
The code depicted below will give us the maximum quantity in stock in the products table.
This will produce the following result.
Gain expertise in the latest Business analytics tools and techniques with the Post Graduate
Program in Business Analysis. Enroll now!
Conclusion
The aggregate function in SQL is very powerful in the database. It serves the same purpose as their
equivalents in MS Excel. In this article, we have seen several examples of aggregate functions.
If you wish to learn more about SQL, then check out our SQL certification course.
This SQL certification course helps you get the basics right with the practical training you need to
https://www.simplilearn.com/tutorials/sql-tutorial/sql-aggregate-functions#:~:text=An aggregate function in SQL performs a calculation on multiple,exc… 8/12
6/3/22, 2:53 PM SQL Aggregate Functions: SUM(), COUNT(), AVG(), Functions
This SQL certification course helps you get the basics right with the practical training you need to
Software Development
work with SQL databases and use them in the applications you use or create. On completing the
course, you will have a work-ready understanding of how to structure your database correctly, create
Articles Ebooks Video Tutorials Live Webinars On-demand Webinars Free Practice Tests
error-free and efficient SQL statements and clauses, and design and manage your SQL databases
for scalable growth.
If you have any questions, please feel free to ask them in our comments section, and our experts will
promptly answer them for you.
Find our Business Analyst Online Bootcamp in top cities:
Name Date Place
Class starts on 18th Jun 2022,
Business Analyst Your City
Weekend batch
Class starts on 20th Jun 2022,
Business Analyst Hyderabad
Weekdays batch
Class starts on 2nd Jul 2022,
Business Analyst Pune
Weekend batch
About the Author
Aryan Gupta
Aryan is a tech enthusiast who likes to stay updated about trending technologies of today. He is
passionate about all things technology, a keen researcher, and writes to inspire. Aside from
technolo…
View More
https://www.simplilearn.com/tutorials/sql-tutorial/sql-aggregate-functions#:~:text=An aggregate function in SQL performs a calculation on multiple,exc… 9/12
6/3/22, 2:53 PM SQL Aggregate Functions: SUM(), COUNT(), AVG(), Functions
Software Development
Articles Ebooks Video Tutorials Live Webinars On-demand Webinars Free Practice Tests
Recommended Programs
Business Analyst Lifetime
Access*
18512 Learners
SQL Training Lifetime
Access*
41209 Learners
*Lifetime access to high-quality, self-paced e-learning content.
Explore Category
Find Business Analyst Master's Program in these cities
Business Analyst Course in Ahmedabad Business Analyst Course in Bangalore Business
Analyst Course in Chennai Business Analyst Course in Coimbatore Business Analyst Course
in Delhi Business Analyst Course in Gurgaon Business Analyst Course in
Hyderabad Business Analyst Course in Jaipur Business Analyst Course in
Kolkata Business Analyst Course in Lucknow Business Analyst Course in
Mumbai Business Analyst Course in Noida Business Analyst Course in Pune Business
Analyst Course in Vijayawada
https://www.simplilearn.com/tutorials/sql-tutorial/sql-aggregate-functions#:~:text=An aggregate function in SQL performs a calculation on multiple,ex… 10/12
6/3/22, 2:53 PM SQL Aggregate Functions: SUM(), COUNT(), AVG(), Functions
Software Development
NEXT ARTICLE
Articles Ebooks Video Tutorials Live Webinars On-demand Webinars Free Practice Tests
Business Analyst vs Data Analyst:
Differences and Career Paths
Explained
By Simplilearn
35862 May 27, 2022
Recommended Resources
Business Intelligence Career Understanding the Ro
Guide: Your Co… IT Business Analy…
0 Comments Simplilearn 🔒 Disqus' Privacy Policy
1 Login
Favorite t Tweet f Share Sort by Best
Start the discussion…
LOG IN WITH
OR SIGN UP WITH DISQUS ?
Name
Be the first to comment.
https://www.simplilearn.com/tutorials/sql-tutorial/sql-aggregate-functions#:~:text=An aggregate function in SQL performs a calculation on multiple,ex… 11/12
6/3/22, 2:53 PM SQL Aggregate Functions: SUM(), COUNT(), AVG(), Functions
Software Development
✉ SubscribeEbooks
Articles d Add Disqus
VideotoTutorials Live Webinars
your siteAdd DisqusAdd On-demand
⚠ Do Not Sell My DataWebinars Free Practice Tests
© 2009 -2022- Simplilearn Solutions
Disclaimer
PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.
https://www.simplilearn.com/tutorials/sql-tutorial/sql-aggregate-functions#:~:text=An aggregate function in SQL performs a calculation on multiple,ex… 12/12