Net Position
A buy adds its qty to the position in a symbol and a sell takes its qty away. Return each symbol once with its position after all trades, in alphabetical order of symbol.
Example 1
trades
| id | symbol | side | qty | price |
|---|---|---|---|---|
| 1 | MSFT | buy | 10 | 410.0 |
| 2 | AAPL | sell | 4 | 191.0 |
| 3 | MSFT | sell | 3 | 412.0 |
| 4 | AAPL | buy | 4 | 189.0 |
returns
| symbol | position |
|---|---|
| AAPL | 0 |
| MSFT | 7 |
Constraints
- Up to 16 trades
sideisbuyorsell
Write it in your browser, against the clock. The model query, with a note on each piece of it, comes after.
More SQL problems
- Orders With NamesEasy
- Pay With BonusEasy
- Small, Medium, LargeEasy
- Total per SymbolEasy
- Totals by MonthEasy
- Above the AverageMedium
- Best Paid in Each DepartmentMedium
- Bought but Never SoldMedium