Without profiling and such, here is the easy route.
Create a stored procedure to do all the work. It will contain more than one statement.
Create a temporary table (see
here) to hold your results. Call this, say, "resultsTable".
Create another temporary table to hold some temporary results. Call this, say "tempTable".
Create a cursor (see
here) that selects each record in the order you want to loop through them (e.g., sort by team).
Use the cursor to loop through each record. Insert each record into tempTable. Store the previous team in a variable and when you encounter a new team (or the end of the records), check tempTable for the "last two" values and insert the result into resultsTable. Clear the tempTable.
Once you have looped through each record, you are done.
Some of that can be optimized, but like I said it's the easy route, so it may be easiest for you to just do this.