आप इसे एक बार में विंडो फ़ंक्शन का उपयोग करके कर सकते हैं। :
; 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)
और यहां Sql Fiddle उदाहरण है ।