Brightlane's buying team is preparing a merchandise budget proposal and needs the total list price across the entire product catalogue.
Write a query to return the summed list price as a single figure named total_catalog_value.
Assumptions:
- The
productstable contains every product in Brightlane's catalogue. - The
pricecolumn is each product's unit list price.
Output:
- A single row with one column,
total_catalog_value, containing the catalogue's combined list price.
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
SUM(price) AS total_catalog_value
FROM
products The shape
SUM(price) adds up the price column across every row in products, returning the total catalog value as a single number. Where COUNT answers "how many rows," SUM answers "what's the total of this column's values across all those rows."
Clause by clause
SELECT SUM(price)is the aggregate. PostgreSQL walks the table, reads each row'spricevalue, and adds them together. The result is one column with one row, holding the total. For Brightlane's current catalog, that total is20574.64. Rows wherepriceisNULLare skipped —SUMonly adds actual numbers, not the absence of a number.AS total_catalog_valuelabels the total as a business quantity. Without the alias, the result column would come back assum— PostgreSQL's default name for the result ofSUM. The alias says what's being summed and in what unit, so the column header doubles as documentation.FROM productsis the source set.SUMneeds a column of numbers; theFROMclause names which table that column lives in.
You practiced reducing a column of values to a single total with SUM. The recurring shape any time a balance, total, or aggregate dollar figure is needed across an entire population.