0
In my SQL Server, have a table containing the registration of odometer of vehicles with the value end of each month.
I need to know what the value that each vehicle toured monthly on the basis of those balances/values.
Detail is that there may be months off the books when the vehicle has been stationary all month, so I have to have the registration with value 0 that month.
Layout of
Tabela: Registros
| Campos |
Placa_Veiculo (string)
AnoMes (AAAA/MM)
KM_fim_Mes (numerico)
If table I have the following data:
placa=a,
ano_mes=2019/01,
km=660;
placa = a,
ano_mes=2019/03,
km=700;
placa=a,
ano_mes=2019/04,
km=780.
My select has to bring 4 lines thus:
placa=a, ano_mes=2019/01, km=660;
placa=a, ano_mes=2019/02, km=0;
placa=a, ano_mes=2019/03, km=40;
placa=a, ano_mes=2019/04, km=80
There is only the table
Registros
?– José Diz
For the vehicle "a", for the month "2019/01" there is no way to calculate how many kilometers traveled as there is no previous information.
– José Diz