Select * from (
Select Name, A, B, some_value, case_id
, ROWNO() over (partition by case_id, Name order by some_value) as R1
from (
Select 'SF' as Name, 'y' as A, 'n' as B, 120 as some_value, 1 as case_id
union all Select 'NY' as Name, 'y' as A, 'n' as B, 150 as some_value, 1 as case_id
union all Select 'LA' as Name, 'y' as A, 'n' as B, 155 as some_value, 1 as case_id
union all Select 'SF' as Name, 'y' as A, 'n' as B, 160 as some_value, 1 as case_id
union all Select 'SF' as Name, 'n' as A, 'y' as B, 110 as some_value, 5 as case_id
union all Select 'NY' as Name, 'n' as A, 'y' as B, 120 as some_value, 5 as case_id
union all Select 'LA' as Name, 'n' as A, 'y' as B, 125 as some_value, 5 as case_id
union all Select 'LA' as Name, 'n' as A, 'y' as B, 140 as some_value, 5 as case_id
union all Select 'NY' as Name, 'n' as A, 'y' as B, 155 as some_value, 5 as case_id
) testdata
) data
Where R1 = 1
order by case_id, some_value