FunctionRacerProblemsRace

Position Over Time

HardSQLSQLite

Trades happen in order of id. A buy adds its qty to the position in its symbol and a sell takes it away. Return every trade's id and symbol, and position: the position in that symbol right after the trade. In order of id.

Example 1

trades
idsymbolsideqty
1AAPLbuy10
2MSFTbuy5
3AAPLsell4
4AAPLsell9
5MSFTbuy1
returns
idsymbolposition
1AAPL10
2MSFT5
3AAPL6
4AAPL-3
5MSFT6

Constraints

Race itor take your time

Write it in your browser, against the clock. The model query, with a note on each piece of it, comes after.

More SQL problems