Practical 7: Aggregrate Functions
2024, May 8
Aggregate functions are essential for summarizing data in SQL. They operate on a set of values and return a single value. Here, we cover key aggregate functions:
Aggregate functions compute results based on a column of numeric data returned by a SELECT
statement. They summarize the results of a selected data column. These functions are integral to the GROUP BY
clause but can also be used independently.
The following examples demonstrate how to use aggregate functions in SQL:
SELECT AVG(salary) FROM employee;
This query returns the average salary of all employees.
SELECT AVG(salary)
FROM employee
WHERE title = 'Programmer';
This query returns the average salary for employees with the title 'Programmer'.
SELECT COUNT(*) FROM employees;
This query returns the number of rows in the employees
table.
items_ordered
table.items_ordered
table.items_ordered
table.SELECT MAX(price) FROM items_ordered;
SELECT AVG(price)
FROM items_ordered
WHERE order_date LIKE '%Dec%';
SELECT COUNT(*) FROM items_ordered;
SELECT MIN(price)
FROM items_ordered
WHERE item = 'Tent';