SQL Aggregate Functions
Summarize many rows with COUNT, SUM, AVG, MIN and MAX.
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.
Calculate total produced quantity, average lead time or the number of open records in a queue.
The pattern
SELECT COUNT(*) AS RowCount,
SUM(Quantity) AS TotalQty
FROM Orders;Example
SELECT COUNT(*) AS OrderCount,
SUM(Quantity) AS TotalUnits
FROM Orders;Run the example
Edit the query and run it against the built-in demo tables. Nothing is sent to a server.
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.
Which function returns the number of rows?
Progress is stored only in this browser. No account required.