SQL COUNT / SUM / AVG / MIN / MAX
Aggregate functions perform calculations on multiple rows and return a single value β ideal for reports, summaries, and analysis. πΉ Syntax & Examples πΉ With GROUP BY π§ Quick Recap Function Description COUNT Count rows (or non-null values) SUM Total of values AVG Average value MIN Smallest value MAX Largest value β Use these to […]
Aggregate functions perform calculations on multiple rows and return a single value β ideal for reports, summaries, and analysis.
πΉ Syntax & Examples
-- β
COUNT: Total number of rows (non-null values in a column)
SELECT COUNT(*) FROM employees;
SELECT COUNT(salary) FROM employees WHERE department = 'IT';
-- β
SUM: Total of a numeric column
SELECT SUM(salary) FROM employees WHERE department = 'HR';
-- β
AVG: Average of a numeric column
SELECT AVG(salary) FROM employees;
-- β
MIN / MAX: Lowest / Highest value
SELECT MIN(salary) FROM employees;
SELECT MAX(salary) FROM employees;πΉ With GROUP BY
-- Average salary per department
SELECT department, AVG(salary)
FROM employees
GROUP BY department;
-- Count of employees in each department
SELECT department, COUNT(*)
FROM employees
GROUP BY department;π§ Quick Recap
| Function | Description |
|---|---|
COUNT | Count rows (or non-null values) |
SUM | Total of values |
AVG | Average value |
MIN | Smallest value |
MAX | Largest value |
β
Use these to summarize and analyze your data
Was this helpful?
Thanks for your feedback!