SQLTeam.com | Weblogs | Forums

Complex CTE query

sql2014

#1


Complex cte query
#2
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

#3

thank you viggneshwar