I have a table where I store invoices of spent fuel and the km's where the car was refueled, with the following structure:

My goal is to obtain a result like the following, so I can calculate the spent km's beetween invoices.

Any advice regarding how I can structure the query to get the desired result?