All Questions
Next Question
Closest Median Profit
00:00:00
Parts
Part 1
The performance review cycle has begun and you are responsible for evaluating the traders at your firm. Out of curiosity, you want to find the two traders that had the closest median profit per trade with one another. Write a SQL query to return the two traders with the closest median profit along with the difference in median profit between the traders. Only include traders that had at least one trade.
Here's an example of how the output should look:
trader1_name | trader2_name | median_profit_diff |
---|---|---|
James | Kendrick | 17 |
You are given the following tables:
traders
Column | Type |
---|---|
id | INTEGER |
name | VARCHAR |
trades
Column | Type |
---|---|
id | INTEGER |
trader_id | INTEGER |
profit | FLOAT |