SyntaxStudy
Sign Up
Home MySQL Reference Aggregate Functions

Aggregate Functions

function

Aggregate functions compute a single result from multiple rows. Used with GROUP BY for grouped summaries.

Syntax

COUNT() SUM() AVG() MIN() MAX()

Example

sql
SELECT
    COUNT(*)           AS total_users,
    COUNT(email)       AS with_email,
    SUM(order_total)   AS revenue,
    AVG(order_total)   AS avg_order,
    MIN(created_at)    AS first_order,
    MAX(created_at)    AS last_order
FROM orders
WHERE status = 'completed';