SQL Tutorial



AGGREGATE FUNCTIONS IN SQL


Aggregate Functions in SQL

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).

๐Ÿงฎ List of Common Aggregate Functions

  • COUNT() โ€“ Counts the number of rows.
  • SUM() โ€“ Returns the sum of a numeric column.
  • AVG() โ€“ Calculates the average of a numeric column.
  • MIN() โ€“ Returns the minimum value.
  • MAX() โ€“ Returns the maximum value.

๐Ÿ“‹ Syntax

SELECT AGGREGATE_FUNCTION(column_name)
FROM table_name
WHERE condition;
  

๐Ÿ’ก Examples

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;

๐Ÿ“Š Using with GROUP BY

You can use aggregate functions to group and summarize data:

SELECT Department, AVG(Salary)
FROM Employees
GROUP BY Department;
  

๐Ÿ“Œ Conclusion

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!


๐ŸŒŸ Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review