Three Largest
Return the id and qty of the three trades with the largest qty, the largest first. Ties go to the smaller id. A table with fewer than three trades returns them all.
Example 1
trades
| id | symbol | qty | price |
|---|---|---|---|
| 1 | AAPL | 10 | 20.0 |
| 2 | MSFT | 50 | 35.5 |
| 3 | AAPL | 70 | 20.0 |
| 4 | KO | 50 | 9.75 |
| 5 | KO | 5 | 9.8 |
returns
| id | qty |
|---|---|
| 3 | 70 |
| 2 | 50 |
| 4 | 50 |
Constraints
- Up to 10 trades
- Ids are unique
Write it in your browser, against the clock. The model query, with a note on each piece of it, comes after.
More SQL problems
- Trade ValueBeginner
- Two ColumnsBeginner
- Average per SymbolEasy
- Biggest SpenderEasy
- Bought and SoldEasy
- Busy SymbolsEasy
- Buyers per ProductEasy
- Customers Without OrdersEasy