SQL Aggregate Functions - SUM, COUNT, AVG, Functions
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
By Aryan Gupta
Table of Contents
COUNT() Function
SUM() Function
AVG() Function
MIN() Function
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.
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.
Count()
Sum()
Avg()
Min()
Max()
EXPLORE PROGRAM
COUNT() Function
Software Development
Syntax:
Articles Ebooks Video Tutorials Live Webinars On-demand Webinars Free Practice Tests
COUNT(*)
or
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.
The below-given command will display those product ids where the unit price is greater than 4.
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.
The SQL command given below will list the number of customers in each city.
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
Syntax:
SUM()
or
Example:
The following SQL statement finds the sum of the "unit price" fields in the "products" table:
Let’s look at how we can use GROUP BY and HAVING functions with the SUM function.
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.
AVG() Function
Syntax:
AVG()
or
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.
MIN() Function
The MIN() aggregate function returns the lowest value (minimum) in a set of non-NULL values.
Syntax:
MIN()
or
Example:
The above code will give us the minimum quantity in stock in the products table.
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
Example:
The code depicted below will give us the maximum quantity in stock in the products table.
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.
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
Software Development
Articles Ebooks Video Tutorials Live Webinars On-demand Webinars Free Practice Tests
Recommended Programs
Explore Category
Analyst Course in Chennai Business Analyst Course in Coimbatore Business Analyst Course
Mumbai Business Analyst Course in Noida Business Analyst Course in Pune Business
Software Development
NEXT ARTICLE
Articles Ebooks Video Tutorials Live Webinars On-demand Webinars Free Practice Tests
By Simplilearn
Recommended Resources
LOG IN WITH
OR SIGN UP WITH DISQUS ?
Name
Software Development
✉ SubscribeEbooks
Articles d Add Disqus
VideotoTutorials Live Webinars
your siteAdd DisqusAdd On-demand
⚠ Do Not Sell My DataWebinars Free Practice Tests
Disclaimer
PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.