Vous pouvez le faire immédiatement en utilisant les fonctions de fenêtre :
; with ordering as (
SELECT max([Range]) AS 'Range'
, count(ID) AS 'Count'
, round(avg([Profit]), 2) AS 'AVG Profit'
, row_number() over (order by avg([Profit])) rn_min
, row_number() over (order by avg([Profit]) desc) rn_max
FROM
Orders
GROUP BY
Range_begining
HAVING COUNT(ID) > 10
)
select [range], [count], [avg profit],
case when rn_max = 1
then 'Max profit'
else 'Min profit'
end Description
from ordering
where (rn_max = 1 or rn_min = 1)
Et voici l'exemple de Sql Fiddle .