LearnSQLSQL Aggregate Functions
ANALYSIS

SQL Aggregate Functions

Summarize many rows with COUNT, SUM, AVG, MIN and MAX.

After this lessonTurn row-level data into useful KPI values.

How it works

Aggregate functions collapse many records into summary values. COUNT measures rows, SUM totals numeric values, AVG returns the arithmetic mean, and MIN/MAX identify extremes.

Aliases with AS give calculated columns readable names. That becomes especially valuable when results feed a report or dashboard.

REAL WORK

Calculate total produced quantity, average lead time or the number of open records in a queue.

SYNTAX

The pattern

SELECT COUNT(*) AS RowCount,
       SUM(Quantity) AS TotalQty
FROM Orders;

Example

SELECT COUNT(*) AS OrderCount,
       SUM(Quantity) AS TotalUnits
FROM Orders;
TRY IT

Run the example

Edit the query and run it against the built-in demo tables. Nothing is sent to a server.

SQL playground

The learning runner supports SELECT, WHERE, LIKE, IN, BETWEEN, GROUP BY, HAVING, JOIN, aggregates, ORDER BY and LIMIT. Advanced lessons explain additional production SQL concepts even when the mini runner does not execute that syntax.

QUICK CHECK

Which function returns the number of rows?

Progress is stored only in this browser. No account required.