Chapter 3 · Lesson 7 of 7

MIN, MAX, and AVG Together

Combine MIN, MAX, and AVG in one SELECT to summarize the spread of a numeric column with its smallest, largest, and average values.

After learning each aggregate separately, you can combine them to get a compact summary of the spread of your data.

SELECT
  MIN(amount) AS smallest_sale,
  MAX(amount) AS largest_sale,
  AVG(amount) AS average_sale
FROM sales

This gives you the lowest value, highest value, and mean in one query. That makes it a useful “quick profile” of a numeric column.

Sample data

This lesson loads the sales table (8 rows) into DuckDB in your browser with one click, so you can run every example without uploading anything.

Setup SQL for sales
CREATE OR REPLACE TABLE sales (
    id INTEGER,
    salesperson VARCHAR,
    region VARCHAR,
    amount DECIMAL(10,2),
    quantity INTEGER,
    sale_date DATE
  );

INSERT INTO sales VALUES
    (1, 'Alice', 'West', 1200, 3, '2024-01-05'),
    (2, 'Bob', 'East', 850, 2, '2024-01-08'),
    (3, 'Alice', 'West', 640, 1, '2024-01-11'),
    (4, 'Diana', 'South', 430, 5, '2024-01-12'),
    (5, 'Eve', 'West', 1500, 4, '2024-02-01'),
    (6, 'Frank', 'East', 920, 2, '2024-02-03'),
    (7, 'Grace', 'North', 760, 2, '2024-02-07'),
    (8, 'Bob', 'East', 1100, 3, '2024-02-10');

Practice challenge

Return the smallest sale as smallest_sale, the largest sale as largest_sale, and the average sale amount as average_sale.

Hint: Use MIN(amount), MAX(amount), and AVG(amount) with the requested aliases.

Run your query in the editor and the lesson checks the result automatically.

Open this lesson in the SQL editor

Lessons in Simple Aggregates

Summarize a whole table into single values with COUNT, SUM, MIN, MAX, and AVG.

  1. 01 · COUNT Rows
  2. 02 · SUM Values
  3. 03 · COUNT and SUM Together
  4. 04 · MIN Finds the Smallest Value
  5. 05 · MAX Finds the Largest Value
  6. 06 · AVG Computes the Mean
  7. 07 · MIN, MAX, and AVG Together

Related guides