SQL Aggregate Functions
SQL Aggregate Functions: Overview and Usage
Aggregate functions in SQL are used to perform calculations on multiple rows of a table and return a single result. They are most commonly used with the SELECT statement to summarize data.
When to Use Aggregate Functions?
Use aggregate functions when you want to get an overview or summary from your data, such as totals, averages, counts, minimums, or maximums.
Common Types of Aggregate Functions
1. COUNT()
Purpose: Counts the number of rows that match a specified condition or counts non-null values in a column.
Example: SELECT COUNT(NAME) FROM EMPLOYEE;
2. SUM()
Purpose: Adds up all the numeric values in a specified column.
Example: SELECT SUM(SALARY) FROM EMPLOYEE;
3. AVG()
Purpose: Calculates the average (mean) of numeric values in a column.
Example: SELECT AVG(SALARY) FROM EMPLOYEE;
4. MIN()
Purpose: Returns the smallest (minimum) value in a column.
Example: SELECT MIN(SALARY) FROM EMPLOYEE;
5. MAX()
Purpose: Returns the largest (maximum) value in a column.
Example: SELECT MAX(SALARY) FROM EMPLOYEE;
Comments
Post a Comment