π SQL Aggregate Functions π Introduction
Aggregate functions in SQL are used to perform calculations on multiple rows of a table and return a single summarized value. They are mainly used to analyze and summarize data in databases.
πΉ Types of Aggregate Functions
COUNT() β Counts the number of rows in a column or table.
SUM() β Returns the total sum of numeric values in a column.
AVG() β Calculates the average of numeric values in a column.
MIN() β Returns the smallest value from a column.
MAX() β Returns the largest value from a column.
πΉ GROUP BY with Aggregate Functions
The GROUP BY clause is used to group rows that have the same values in specified columns. Aggregate functions are then applied to each group separately.
πΉ HAVING with Aggregate Functions
The HAVING clause is used to filter groups based on aggregate conditions. It works like the WHERE clause, but is applied after grouping.
β Summary
Aggregate functions operate on multiple rows and return a single value.
Common functions include COUNT, SUM, AVG, MIN, and MAX.
They are often used with GROUP BY to summarize data by categories.
The HAVING clause is used to filter groups based on aggregated results.