Streamhub is tracking software vendor spend ahead of next quarter's budget review. A procurement analyst is documenting the cost of one analytics tool that is billed at $29.99 per month on a monthly cycle.
Write a query to return the total cost for a 12-month subscription.
Output:
- A single row with one column,
annual_cost.
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
29.99 * 12 AS annual_cost The shape
The multiplication inside the SELECT rolls a monthly cost into an annual one, and AS annual_cost makes the result readable in the business unit the procurement analyst is working in.
Clause by clause
SELECT 29.99 * 12evaluates the multiplication once and returns359.88. There's noFROMbecause there's no table to read from; the rate and the cycle length come straight from the prompt as literals. The result carries two decimal places because29.99does — when PostgreSQL multiplies anumericby an integer, it keeps the scale of the more precise operand. So the dollars-and-cents precision survives the calculation intact.AS annual_costlabels the output column so the result reads as a domain quantity. Without it, the column would land as?column?in the budget review — readable to the analyst running the query, useless to anyone else looking at the screenshot later. Labelling at the source is what makes a one-off calculation portable into a report or a spreadsheet without renaming it after the fact.
You practiced multiplying inside a SELECT and labeling the result with AS. The same shape recurs anytime a computed value needs a clear name in the result.