select a.KmEnd as CurrentMileage, b.KmEnd as PreviousMileage
from RouteAvtovozi a Inner Join RouteAvtovozi b on
a.RegNo = b.RegNo
where a.KomNo = <Current KomNo>
and b.KomNo < a.KomNo
and not exists (
select * from RouteAvtovozi c
where c.RegNo = a.RegNo
and c.KomNo > b.KomNo
and c.KomNo < a.KomNo)