my table looks like this:
| Home team | Away team | Home index | Away index | home rolling score | away rolling score | |
|---|---|---|---|---|---|---|
| Philadelphia | Atlanta | 1 | 0 | 0 | 0 | |
| New York | Houston | 0 | 1 | 0 | 0 | |
| Denver | Orlando | 1 | 0 | 0 | 0 | |
| Philadelphia | Atlanta | 1 | 0 | 1 | 0 | |
| New York | Houston | 0 | 1 | 0 | 1 | 1 |
| Los Angeles | Atlanta | 1 | 0 | 0 | 0 | |
| Philadelphia | Atlanta | 1 | 0 | 2 | 0 | |
| New York | Philadelphia | 0 | 1 | 0 | 3 | |
| San Antonio | Dallas | 1 | 0 | 1 | 0 | |
| Philadelphia | Atlanta | 1 | 0 | 3 | 0 | |
| New York | Philadelphia | 0 | 1 | 0 | 3 | |
| Miami | Boston | 1 | 0 | 1 | 0 | |
| Philadelphia | Atlanta | 1 | 0 | 1 | 0 | |
| New York | Houston | 0 | 1 | 0 | 1 |
I would like to get a rolling sum for last 3 results for Philadelphia for example for all of their matches, so if they played at home then the home index number should count, if they played away, away index should count.
The result should come in another column where the home team has calculated their rolling sum and also do the same for away team until that row (not including that row). This means in every row the query will look for a home team and calculate the rolling sum until that row. So as in the example you can see home rolling score and away rolling score. If you check the Philadelphia score, it's 0 in the first row because there are no records before then in the next game of Philadelphia it's 1 because that's the sum of their previous games and in row 10 where there is game Philadelphia vs Atlanta, the rolling sum for home is 3 which is the sum of last 3 rows for Philadelphia without counting that row.
Any help how can I achieve this is much appreciated.


