Подскажите, как лучше и нужно ли избавляться от подзапроса для ускорения?
SELECT
CONCAT('property', units.property_id, '_channel', reservation_sources.channel_id) as 'key',
MAX(temp.count_of_days) AS 'count_of_days'
FROM
( SELECT
l.id,
COUNT(c2.id) AS 'count_of_days'
FROM
calendar_price c2
INNER JOIN units u ON u.id = c2.unit_id
INNER JOIN listing_type_units ltu ON ltu.unit_id = u.id
INNER JOIN units l ON l.listing_type_id = ltu.listing_type_id
WHERE
c2.day BETWEEN '2021-01-01' AND '2021-10-30' AND c2.rate_plan_id = u.rate_plan_id
GROUP BY l.id) AS temp
INNER JOIN units ON units.id = temp.id
INNER JOIN reservation_sources ON reservation_sources.id = units.reservation_source_id
GROUP BY 'key';