I know this is very old, but thought it should be indicated.
select car_id, max_version from (select car_id , version , max(version) over (partition by car_id) as max_version from car ) max_ver where max_ver.version = max_ver.max_version
Not sure why you made option 2 like this ... in this case sub select should be theoretically slower because you select 2x from the same table and then attach the results to yourself.
Just remove the version from your inline view, and it's the same.
select car_id, max(version) over (partition by car_id) as max_version from car
Performance really depends on the optimizer in this situation, but yes, as the original answer offers inline views, as they reduce the results. Although this is not a very good example, this is its same table without filters in the selected parameters.
Separation is also useful when you select a large number of columns, but need different aggregates that match the result set. Otherwise, you have to group all the other columns.
source share