Back to Practice
#0027

Categories Over Revenue Threshold

EasySQL12 min10 XP

Problem

Write a query that returns categories whose total revenue is at least 500. Revenue is price multiplied by quantity.

Why This Matters

HAVING is the filter you use after aggregation. Many beginners incorrectly put aggregate filters in WHERE.

Schema

order_items(category, price, quantity)

Examples

Example 1
Inputbooks total 700, pens total 80, bags total 500
Outputbooks and bags

Only categories with total revenue at least 500 remain.

Constraints

  • Return category and total_revenue.
  • Sort by total_revenue descending.
  • Use HAVING for the aggregate filter.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 4 hidden categories
Filters after grouping
Inputthree categories with different total revenue
Expectedbooks then bags

Pens are filtered out after aggregation.

Hidden Test Categories
Category exactly at thresholdSingle categoryMultiple rows per categoryNo category crosses threshold