SUM & AVG: Total Revenue and Average Price by Category

Basics
BasicsGROUP BYSUMAVGGoogleAmazonMeta

Table

  • sales(sale_id INT, category VARCHAR, price INT)

Task

From sales(sale_id, category, price), return category, total_revenue (SUM(price)), and avg_price (AVG(price)), ordered by category ASC.

Why It Matters: Aggregating SUM and AVG per category powers executive revenue and average-order-value (AOV) reporting.

Output columns: category, total_revenue, avg_price

Example

Input — sales

sale_idcategoryprice
1Tech100
2Tech200
3Books20
4Books40

Expected Output

categorytotal_revenueavg_price
Books6030
Tech300150

Explanation: Computes total revenue and average price within each category, ordered cleanly by category.

Requirements

  • Exact output columns: category, total_revenue, avg_price
  • Row order: Exact ORDER BY order is checked by the grader.
  • Query type: Write a single read-only Standard SQL SELECT (or WITH ... SELECT) query.

Constraints & Evaluation Criteria

  • Return `category, total_revenue, avg_price` ordered by `category ASC`.

Hints

SQL
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
sales (4 rows)
Expected Output / Criteria
2 row(s): (Books, 60, 30.0); (Tech, 300, 150.0)