Chapter 3 · Lesson 1 of 7
COUNT Rows
Count rows with COUNT(*) and combine it with WHERE to answer how-many questions, such as how many sales a single region recorded.
COUNT tells you how many rows match a condition. It is one of the fastest ways to answer questions like “How many sales did we make?” or “How many sales came from the West region?”
The most common form is COUNT(*):
SELECT COUNT(*) AS sale_count
FROM salesCOUNT(*) counts rows. COUNT(column_name) counts only rows where that column is not NULL.
You can also add a WHERE clause to count only part of a table.
SELECT COUNT(*) AS sale_count
FROM sales
WHERE region = 'West'COUNT is often the first aggregate people learn because it turns many rows into one simple summary value.
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 number of East region sales as sale_count.
Hint: Use COUNT(*) with WHERE region = 'East'.
Run your query in the editor and the lesson checks the result automatically.
Lessons in Simple Aggregates
Summarize a whole table into single values with COUNT, SUM, MIN, MAX, and AVG.
Related guides
SQL Aggregate Functions: COUNT, SUM, MIN, MAX, and AVG Explained
Aggregate functions turn many rows into useful summary values, which is the foundation of reporting, dashboards, and quick data checks.
Parquet vs CSV for SQL Analysis: Types, Columnar Reads, and Memory Limits
Parquet stores typed columns that engines can read selectively. See what that means for SQL analysis and where browser memory still sets the limit.
What Is DuckDB WASM and Why Use It for Browser SQL?
DuckDB WASM brings an analytical SQL engine into the browser, enabling local file analysis without a server-side database.