Tools

SQL COUNT / SUM / AVG / MIN / MAX

Share:
Article Summary

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

FunctionDescription
COUNTCount rows (or non-null values)
SUMTotal of values
AVGAverage value
MINSmallest value
MAXLargest value

βœ… Use these to summarize and analyze your data

Was this helpful?

Written by

W3buddy
W3buddy

Explore W3Buddy for in-depth guides, breaking tech news, and expert analysis on AI, cybersecurity, databases, web development, and emerging technologies.