Aggregating data
Statistical calculation is done through aggregate functions. Aggregate functions take in one or more columns with multiple rows and return a number based on those columns. To use aggregate functions, you simply put them in the SELECT statement with the designated table and column on which you want to aggregate. For example, this SQL returns the latest hire date of all salespeople:
SELECT MAX(hire_date) FROM salespeople;
Here, the max function looked at all the values in the hire_date column and returned the max value (i.e, the latest date). The following shows how the output appears:
max
---------------------
2024-10-20 00:00:00
The following table provides a summary of the major aggregate functions that are used in SQL:
|
Function |
Explanation |
|---|---|
|
|
Counts... |