Aggregate functions in SQL are used to perform calculations on multiple rows of a tableโs column and return a single value. These are often used with GROUP BY
and HAVING
clauses to group data and filter grouped records.
๐ Tip: Aggregate functions ignore NULL
values (except COUNT(*)
which counts all rows).
SELECT AGGREGATE_FUNCTION(column_name) FROM table_name WHERE condition;
1. Count total customers:
SELECT COUNT(*) FROM Customers;
2. Get average price of products:
SELECT AVG(Price) FROM Products;
3. Find highest salary:
SELECT MAX(Salary) FROM Employees;
You can use aggregate functions to group and summarize data:
SELECT Department, AVG(Salary) FROM Employees GROUP BY Department;
Aggregate functions are essential tools in SQL to summarize and analyze large amounts of data. Whether counting records, summing values, or calculating averages, they help turn raw data into useful insights.
โ Next Step: Try using multiple aggregate functions in one query to generate powerful reports!
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!