# Top Industries by Won Revenue

**Type:** SOQL · **Difficulty:** Hard · **Topics:** GROUP BY, HAVING, Parent Field Aggregate

Practice this problem interactively (write and run your SOQL against realistic data): https://www.forcechallenges.com/problems/top-industries-won-revenue

## Problem

**Scenario**
Sales leadership wants to know which customer industries bring in the most closed revenue. Every Opportunity belongs to an Account, and every Account has an Industry.

**Task**
Write one SOQL query on `Opportunity` that:
1. Uses only **won** Opportunities (`IsWon = true`).
2. Groups them by the parent Account's industry (`Account.Industry`).
3. Keeps only industries whose **total won `Amount` is greater than 1,000,000**.
4. Sorts industries by that total, **highest first**.
5. Returns at most the **top 5** industries.

**Expected output**
One row per industry with two columns: `Account.Industry` and the total won amount. Leave the total un-aliased so it comes back as `expr0`.

**Example**
Won Opportunities: Retail 600,000 + 700,000, Finance 1,500,000, Healthcare 400,000.
- Finance total 1,500,000 qualifies and ranks first.
- Retail total 1,300,000 qualifies and ranks second.
- Healthcare total 400,000 does not exceed 1,000,000, so it is excluded.

Result: Finance (1,500,000), then Retail (1,300,000).

## Constraints

Use one query with GROUP BY on a parent field, HAVING on an aggregate, ORDER BY on an aggregate, and LIMIT. Filter on IsWon, not on StageName text.

---
Source: ForceChallenges · last updated 2026-10-23
