Brightlane's operations team is building a weekly capacity report and needs a baseline order-volume figure.
Write a query to return the total number of orders the platform has processed in a single column named order_count.
Assumptions:
- The
orderstable contains every order Brightlane has processed. - Every row in
ordersrepresents one order; the count is simply the row count.
Output:
- A single row with one column,
order_count, containing the total order count.
Schema · ecommerce 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
COUNT(*) AS order_count
FROM
orders The shape
COUNT(*) collapses every row of the orders table down to a single number — the total count of orders Brightlane has processed. An aggregate query always returns exactly one row of summary numbers, regardless of how many rows live in the source table.
Clause by clause
SELECT COUNT(*)is the aggregate. The*means "every row," so PostgreSQL walks the table, counts rows as it goes, and returns one number. The result row has one column whether the underlying table has zero, three, or three million rows. For this dataset, the count is200.AS order_countlabels that single number as the domain quantity. Without it, the column would come back ascount— PostgreSQL's default name for the result ofCOUNT. The alias makes the result self-documenting: anyone reading the column header knows what was counted.FROM ordersis whatCOUNT(*)reads from. Aggregates always need to know which set of rows to collapse, and theFROMclause provides that set.
You practiced collapsing an entire table to a single number with COUNT(*). The recurring shape: when the question is "how many rows," COUNT(*) reads every row's existence — column values are irrelevant.