Your question is SQL: Top Companies by Revenue. Start with the requirements and the three tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Lumenalta needs a revenue leaderboard for fiscal year 2025. Write a PostgreSQL query that calculates each company's net settled revenue after refunds, ranks companies by revenue, and includes every company tied within the top three rank positions.
status = 'SETTLED' dated from 2025-01-01 through 2025-12-31.companies: Aster Systems, BluePeak Labs, Cedar Health, Delta Freight, Ember Retail, Fathom Media, Lumenalta, Northstar Energy.
revenue_transactions: settled gross amounts include Aster transactions of 1000 and 500, BluePeak transactions of 900 and 600, Cedar transactions of 1200 and 300, Delta of 1499, Ember of 1300, and Lumenalta of 1600. A pending BluePeak transaction and an out-of-period Aster transaction must be excluded.
revenue_adjustments: Lumenalta has 100 in refunds, Ember has 100 in refunds, and Aster, BluePeak, and Cedar have zero or null adjustments. Include an adjustment for an unknown transaction to test join behavior.
| Column | Type | Description |
|---|---|---|
| company_idPK | INT | Unique company identifier |
| company_name | VARCHAR(100) | Company display name |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique revenue transaction identifier |
| company_id | INT | Company associated with the transaction |
| transaction_date | DATE | Date the transaction was recorded |
| gross_amount | NUMERIC(12,2) | Gross transaction amount before refunds |
| status | VARCHAR(20) | Settlement status |
| Column | Type | Description |
|---|---|---|
| adjustment_idPK | INT | Unique adjustment identifier |
| transaction_id | INT | Transaction receiving the adjustment |
| adjustment_type | VARCHAR(20) | Adjustment category |
| amount | NUMERIC(12,2) | Refund amount |