我的以下查询有点慢,您可以看到 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