Bought and Sold
Return each symbol once with bought, the total qty of its buys, and sold, the total qty of its sells. A symbol with no sells has sold 0, and likewise for buys. Rows may come in any order.
Example 1
trades
| id | symbol | side | qty | price |
|---|---|---|---|---|
| 1 | AAPL | buy | 10 | 190.5 |
| 2 | AAPL | sell | 4 | 191.0 |
| 3 | MSFT | buy | 5 | 410.0 |
| 4 | AAPL | buy | 1 | 189.0 |
returns
| symbol | bought | sold |
|---|---|---|
| AAPL | 11 | 4 |
| MSFT | 5 | 0 |
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.