sql >> Base de Datos >  >> RDS >> Sqlserver

Cómo encontrar registros máximos para un rango dado

Solo usa group by :

select (case when distance <= 100 then 'group 1'
             when distance <= 1000 then 'group 2'
             else '!?!'
        end) as range_group,
       max(rate)
from t
group by (case when distance <= 100 then 'group 1'
               when distance <= 1000 then 'group 2'
               else '!?!'
          end);