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_id | category | price |
|---|---|---|
| 1 | Tech | 100 |
| 2 | Tech | 200 |
| 3 | Books | 20 |
| 4 | Books | 40 |
Expected Output
| category | total_revenue | avg_price |
|---|---|---|
| Books | 60 | 30 |
| Tech | 300 | 150 |
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 BYorder is checked by the grader. - Query type: Write a single read-only Standard SQL
SELECT(orWITH ... SELECT) query.
Constraints & Evaluation Criteria
- Return `category, total_revenue, avg_price` ordered by `category ASC`.
Hints
SQL⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
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)