Top Three Pipeline Deals
Basic SolvedThe weekly forecast call opens with the three biggest deals in the pipeline.
Return Name and Amount of the three Opportunities with the largest Amount, largest first.
Sample data
Opportunity 5 records
| Name | StageName | Amount | CloseDate |
|---|---|---|---|
| Atlas renewal | Prospecting | 75,000 | today + 30 days |
| Beacon pilot | Qualification | 20,000 | today + 30 days |
| Cobalt rollout | Negotiation/Review | 120,000 | today + 30 days |
| Delta expansion | Qualification | 51,000 | today + 30 days |
| Ember upgrade | Prospecting | 98,000 | today + 30 days |
Expected result on the sample
| Name | Amount |
|---|---|
| Cobalt rollout | 120,000 |
| Ember upgrade | 98,000 |
| Atlas renewal | 75,000 |
Row order matters for this problem. Only the columns above are compared; extra columns in your SELECT are fine.
Hints
- Sort descending with
ORDER BY Amount DESC. LIMIT 3keeps the first three rows after sorting.
What this tests
ORDER BY with LIMIT is how you ask the database for "top N" instead of fetching everything and sorting in Apex, which wastes query rows and heap. The direction matters: ascending is the default, so a "largest first" list needs DESC.
Datasets
Solved on this device only. Sign in with Google to keep your progress across devices.
Run on sample executes your query against the sample data shown on the left and displays the rows it returns. Submit checks it against the sample plus 2 hidden datasets, comparing your rows with the expected rows on each. Queries run in a real Salesforce org; the data is inserted for your run and rolled back afterwards.