Volume Weighted Price
The volume weighted average price of a symbol is the money traded in it (the sum of qty times price) divided by the quantity traded (the sum of qty). Return each symbol once with vwap, rounded to 2 decimals. Rows may come in any order.
Example 1
trades
| id | symbol | qty | price |
|---|---|---|---|
| 1 | AAPL | 10 | 190.0 |
| 2 | MSFT | 5 | 410.0 |
| 3 | AAPL | 30 | 194.0 |
returns
| symbol | vwap |
|---|---|
| AAPL | 193.0 |
| MSFT | 410.0 |
Constraints
- Up to 16 trades
- No result is a close call for the rounding
Write it in your browser, against the clock. The model query, with a note on each piece of it, comes after.
More SQL problems
- Chain of CommandHard
- Daily BarsHard
- Longest Winning StreakHard
- Median SalaryHard
- Month Over MonthHard
- Moving AverageHard
- Position Over TimeHard
- SessionsHard