Я считаю, что это должно работать.
select Month, 'Most Frequent' from (
select *, row_number() over (partition by Month order by Frequency desc) rnk from (
SELECT
MONTH(b.BookingStartDateTime) AS 'Month',
f.FacilityDesc AS 'MOST FREQUENT',
count(*) as 'Frequency'
FROM
Booking b
INNER JOIN
Facility f ON b.FacilityID = f.FacilityID
WHERE
YEAR(b.BookingStartDateTime) = 2017
GROUP BY
MONTH(b.BookingStartDateTime), f.FacilityDesc
) rnk
) a where rnk = 1
order by month desc
Добавлена неоконная версия функции, вам нужно выполнить внутреннее объединение или где есть метод, чтобы получить ваш результат
with rnk as (
SELECT
MONTH(b.BookingStartDateTime) AS 'Month',
f.FacilityDesc AS 'MOST FREQUENT',
count(*) as 'Frequency'
FROM
Booking b
INNER JOIN
Facility f ON b.FacilityID = f.FacilityID
WHERE
YEAR(b.BookingStartDateTime) = 2017
GROUP BY
MONTH(b.BookingStartDateTime), f.FacilityDesc
)
select Month, 'Most Frequent' from rnk where exists(
select Month, freq from (
select Month, max(Frequency) freq from rnk group by Month
) a where a.Month = rnk.Month and a.freq = rnk.Frequency
)
order by Month desc