By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
my_date | my_shares | stock_price | new_shares |
---|---|---|---|
2021-01-01 | 100 | 11 | 100 |
2021-01-02 | 100 | 11 | 0 |
2021-01-03 | 100 | 11 | 0 |
2021-01-04 | 150 | 12 | 50 |
2021-01-05 | 175 | 13 | 25 |
my_date | my_shares | stock_price | new_shares | grp | my_cost |
---|---|---|---|---|---|
2021-01-01 | 100 | 11 | 100 | 1 | 1100 |
2021-01-02 | 100 | 11 | 0 | 1 | 1100 |
2021-01-03 | 100 | 11 | 0 | 1 | 1100 |
2021-01-04 | 150 | 12 | 50 | 1 | 600 |
2021-01-05 | 175 | 13 | 25 | 1 | 325 |