Hi there, we’re Harisystems

"Unlock your potential and soar to new heights with our exclusive online courses! Ignite your passion, acquire valuable skills, and embrace limitless possibilities. Don't miss out on our limited-time sale - invest in yourself today and embark on a journey of personal and professional growth. Enroll now and shape your future with knowledge that lasts a lifetime!".

For corporate trainings, projects, and real world experience reach us. We believe that education should be accessible to all, regardless of geographical location or background.

1
1

MySQL Aggregate Functions

Introduction

Aggregate functions in MySQL allow you to perform calculations on sets of values and return a single value as a result. They are commonly used to obtain summary information from tables or subsets of data. In this article, we will explore the usage of aggregate functions in MySQL with examples to illustrate their functionality.

COUNT()

The COUNT() function is used to count the number of rows in a table or a subset of data. Here's an example that counts the number of employees:

SELECT COUNT(*) FROM employees;

SUM()

The SUM() function is used to calculate the sum of a column or a set of values. Here's an example that calculates the total salary of all employees:

SELECT SUM(salary) FROM employees;

AVG()

The AVG() function is used to calculate the average value of a column or a set of values. Here's an example that calculates the average salary of all employees:

SELECT AVG(salary) FROM employees;

MIN()

The MIN() function is used to find the minimum value of a column or a set of values. Here's an example that retrieves the lowest salary among employees:

SELECT MIN(salary) FROM employees;

MAX()

The MAX() function is used to find the maximum value of a column or a set of values. Here's an example that retrieves the highest salary among employees:

SELECT MAX(salary) FROM employees;

GROUP BY

The GROUP BY clause is used in combination with aggregate functions to perform calculations on subsets of data. It groups the data based on one or more columns. Here's an example that calculates the total sales amount per customer:

SELECT customer_id, SUM(amount) FROM orders GROUP BY customer_id;

HAVING

The HAVING clause is used in combination with the GROUP BY clause to filter the results of the grouped data based on conditions. Here's an example that retrieves customers with a total sales amount greater than 1000:

SELECT customer_id, SUM(amount) FROM orders GROUP BY customer_id HAVING SUM(amount) > 1000;

Conclusion

Aggregate functions are essential in MySQL for performing calculations on sets of data and obtaining summary information. In this article, we explored the usage of COUNT(), SUM(), AVG(), MIN(), and MAX() functions, as well as the GROUP BY and HAVING clauses. By leveraging aggregate functions, you can extract meaningful insights and statistics from your MySQL databases.

4.5L

Learners

20+

Instructors

50+

Courses

6.0L

Course enrollments

4.5/5.0 5(Based on 4265 ratings)

Future Trending Courses

When selecting, a course, Here are a few areas that are expected to be in demand in the future:.

Beginner

The Python Course: Absolute Beginners for strong Fundamentals

By: Sekhar Metla
4.5 (13,245)
Intermediate

JavaScript Masterclass for Beginner to Expert: Bootcamp

By: Sekhar Metla
4.5 (9,300)
Intermediate

Python Coding Intermediate: OOPs, Classes, and Methods

By: Sekhar Metla
(11,145)
Intermediate

Microsoft: SQL Server Bootcamp 2023: Go from Zero to Hero

By: Sekhar Metla
4.5 (7,700)
Excel course

Future Learning for all

If you’re passionate and ready to dive in, we’d love to join 1:1 classes for you. We’re committed to support our learners and professionals their development and well-being.

View Courses

Most Popular Course topics

These are the most popular course topics among Software Courses for learners