Complex CTE query

select a.version, a.car, a.Type, a.distance, case when a.Type='old' then b.distance - a.distance end as Delta
from table a
inner join (select car, min(distance) distance from table where Type='new' group by car) b
on a.car = b.car
1 Like

thank you viggneshwar