SQL Aggregate Functions – COUNT, SUM, AVG, MIN, MAX




💻 Introduction

Aggregate functions in SQL perform calculations on multiple rows and return a single value. They are often used with GROUP BY for summarizing data.

🔑 Common Aggregate Functions

  • COUNT() – Counts rows
  • SUM() – Calculates total
  • AVG() – Finds average
  • MIN() – Finds smallest value
  • MAX() – Finds largest value

📝 Example

SELECT 
  COUNT(*) AS total_employees,
  SUM(salary) AS total_salary,
  AVG(salary) AS avg_salary,
  MIN(salary) AS lowest_salary,
  MAX(salary) AS highest_salary
FROM Employees;
Tip: Aggregate functions ignore NULL values (except COUNT(*)).

✅ Key Takeaways

  • Aggregate functions summarize data
  • Often used with GROUP BY and HAVING
  • They return a single value per group or query

📚 Continue Learning

💬 Questions about Aggregate Functions? Drop a comment!




Leave a Comment