Brightlane's merchandising team is evaluating margin on a new product line ahead of the spring catalog launch. One item in the line sells for $149.99 and carries a production cost of $89.50 per unit.
Write a query to return the gross profit per unit.
Output:
- A single row with one column,
gross_profit.
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
149.99 - 89.50 AS gross_profit The shape
The subtraction inside the SELECT does the work, and the AS alias makes the result readable as a business quantity instead of a math expression.
Clause by clause
SELECT 149.99 - 89.50evaluates the subtraction once and returns60.49. There's noFROMbecause there's no table to read from; the two values come straight from the prompt as literals —149.99for the sale price,89.50for the production cost. The result carries two decimal places because both inputs do; PostgreSQL infers the scale of a numeric expression from its operands.AS gross_profitlabels the output column so the result reads as a domain quantity. Without it, PostgreSQL would label the column?column?, which is fine for a quick check but useless once the result has to feed anything downstream — a spreadsheet, a report, another query.
You practiced returning a labeled expression with AS. Naming computed columns is the foundation for every query that produces derived values.