Revenue Ladder, Unknowns Last
Intermediate SolvedFinance is building a revenue ladder from the smallest customer to the largest. Accounts with no revenue figure should sit at the bottom, not the top.
Return the Name of every Account ordered by AnnualRevenue from smallest to largest, with accounts that have no revenue value at the end.
Sample data
Account 4 records
| Name | AnnualRevenue |
|---|---|
| Acme Cloud | 5,000,000 |
| Bluefin Bank | null |
| Corex Labs | 1,200,000 |
| Delta Retail | 9,000,000 |
Expected result on the sample
| Name |
|---|
| Corex Labs |
| Acme Cloud |
| Delta Retail |
| Bluefin Bank |
Row order matters for this problem. Only the columns above are compared; extra columns in your SELECT are fine.
Hints
- Ascending is the default direction.
- Add
NULLS LASTafter the sort direction.
What this tests
In an ascending sort, SOQL puts null values first by default. NULLS LAST moves them to the end without a second query or any Apex. Forgetting it is a common reason a sorted list "looks wrong" in a report or a Lightning table.
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.