SELECT DISTINCT TOP 50 count(sce.StateId) as StateChanges,
m.DisplayName as MonitorName,
m.Name as MonitorId,
mt.typename AS TargetClass
FROM StateChangeEvent sce with (nolock)
join state s with (nolock) on sce.StateId = s.StateId
join monitorview m with (nolock) on s.MonitorId = m.Id
join managedtype mt with (nolock) on m.TargetMonitoringClassId = mt.ManagedTypeId
where m.IsUnitMonitor = 1
-- Scoped to within last 7 days
AND sce.TimeGenerated > dateadd(dd,-1,getutcdate())
group by m.DisplayName, m.Name,mt.typename
order by StateChanges desc