Closest Median Profit Between Traders
You are evaluating traders at your firm during a performance review. You want to find the two traders whose median profit per trade is closest to each other.
Write a SQL query that returns the pair of traders with the smallest absolute difference in median profit per trade. Only include traders who made at least one trade. Output columns: `trader1_name`, `trader2_name`, `median_profit_diff`.
**Tables:**
`traders`
| Column | Type |
|--------|---------|
| id | INTEGER |
| name | VARCHAR |
`trades`
| Column | Type |
|-----------|---------|
| id | INTEGER |
| trader_id | INTEGER |
| profit | FLOAT |
**Example output:**
| trader1_name | trader2_name | median_profit_diff |
|--------------|--------------|--------------------|
| James | Kendrick | 17 |
Open the full interactive solver, hints, and worked solution →