SQL Practice Logo

SQLPractice Online

COUNT, SUM, AVG, MIN, MAX: Examples

Module: Aggregate Functions & Grouping

Overall Sales Report

basic

Finance needs overview of all orders - count, total revenue, average order value, and range.

SELECT

COUNT(*) AS total_orders,

SUM(total_amount) AS total_revenue,

AVG(total_amount) AS avg_order_value,

MIN(total_amount) AS smallest_order,

MAX(total_amount) AS largest_order

FROM orders;

total_orders | total_revenue | avg_order_value | smallest_order | largest_order

1250 | 487500.00 | 390.00 | 15.50 | 5200.00

All aggregates computed in one table scan. COUNT counts all rows, SUM adds amounts, AVG calculates mean, MIN/MAX find extremes.

All