Aggregate Functions
SQL (Structured Query Language) is a standard language used to manage and manipulate relational databases. Aggregate functions and indexes are important features of SQL that help to make database queries more efficient and effective.
Aggregate Functions
Aggregate functions are used to perform calculations on a set of values and return a single value. Here are some of the commonly used aggregate functions in SQL:
COUNT
The COUNT function returns the number of rows that match a specified condition. It can be used with or without a WHERE clause.
Example:
This will return the total number of rows in the 'customers' table.
SUM
The SUM function returns the sum of a numeric column in a table. It can be used with or without a WHERE clause.
Example:
This will return the total sum of prices for completed orders.
AVG
The AVG function returns the average of a numeric column in a table. It can be used with or without a WHERE clause.
Example:
This will return the average age of employees in the sales department.
MIN
The MIN function returns the minimum value of a column in a table. It can be used with or without a WHERE clause.
Example:
This will return the minimum salary of employees in the finance department.
MAX
The MAX function returns the maximum value of a column in a table. It can be used with or without a WHERE clause.
Example:
This will return the maximum sales value for the year 2022.
Last updated
Was this helpful?