where句にネストされたクエリがいくつかあることがわかるように、次のクエリは少し遅いですが、より良い解決策を思い付くことができますか?
SELECT m.briefmedialist,
Count(DISTINCT s.value) AS selected,
m.briefmedialistid
FROM vwmedialistmediachannels m
LEFT JOIN sessionfilters s
ON s.field = 'Media'
AND m.briefmedialistid = s.value
AND s.sessionid = @SessionID
WHERE m.id = (SELECT d.briefid
FROM dashboards d
WHERE d.dashboardguid IN (SELECT value
FROM sessionfilters s
WHERE s.sessionid = @SessionID
AND s.field = 'DashboardID'))
GROUP BY m.briefmedialist,
m.briefmedialistid
ORDER BY m.briefmedialist