Last Updated: 23 June, 2023
MySQL aggregate functions are special functions used in SQL queries to perform calculations on a set of rows and return a single value as the result. These functions operate on a group of rows and summarize or combine the data in some way.
Here are some commonly used MySQL aggregate functions:
COUNT: It returns the number of rows that match a specified condition.
Example:
SELECT COUNT(*) FROM customers;
SUM: It calculates the sum of a numeric column for the selected rows.
Example:
SELECT SUM(price) FROM orders;
AVG: It calculates the average value of a numeric column for the selected rows.
Example:
SELECT AVG(quantity) FROM products;
MIN: It retrieves the minimum value from a column for the selected rows.
Example:
SELECT MIN(price) FROM products;
MAX: It retrieves the maximum value from a column for the selected rows.
Example:
SELECT MAX(quantity) FROM orders;
GROUP_CONCAT: It concatenates the values of a column into a single string, separated by a specified delimiter.
Example:
SELECT GROUP_CONCAT(product_name SEPARATOR ', ') FROM products;;
These aggregate functions are typically used in conjunction with the GROUP BY clause to group the data based on specific criteria. For example, we can calculate the total sales for each product category by combining the SUM function with the GROUP BY clause.
That's all, guys. I hope this MySQL article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com