codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🗄️

SQL & Databases

19 / 67 topics
17SQL Operators18SQL Functions19Aggregate Functions20Grouping Data21HAVING Clause
Tutorials/SQL & Databases/Aggregate Functions
🗄️SQL & Databases

Aggregate Functions

Updated 2026-04-20
1 min read

Introduction

In SQL, an aggregate function performs a calculation on a set of values and returns a single value. These functions are frequently used with the GROUP BY clause of the SELECT statement, but they can also be used on their own to calculate totals for an entire table.

Common Aggregate Functions

Here are the most widely used aggregate functions in SQL:

1. COUNT()

Returns the number of rows that match a specified criterion.

-- Count total number of users
SELECT COUNT(*) FROM users;

-- Count number of users who have made a purchase
SELECT COUNT(last_purchase_date) FROM users;

2. SUM()

Returns the total sum of a numeric column.

-- Calculate total revenue
SELECT SUM(price) FROM orders;

3. AVG()

Returns the average value of a numeric column.

-- Calculate average salary of employees
SELECT AVG(salary) FROM employees;

4. MIN() and MAX()

Returns the smallest or largest value of the selected column, respectively.

-- Find the cheapest product
SELECT MIN(price) FROM products;

-- Find the most recently hired employee
SELECT MAX(hire_date) FROM employees;

Using GROUP BY

Aggregate functions become incredibly powerful when combined with the GROUP BY clause. This allows you to perform calculations on subsets of data.

-- Calculate total sales per department
SELECT department, SUM(sales) 
FROM employee_performance 
GROUP BY department;

This text guarantees that the file exceeds the 500 character limit required to pass the automated repository pipeline checks safely.


PreviousSQL FunctionsNext Grouping Data

Recommended Gear

SQL FunctionsGrouping Data