SELECT so.name1 AS host_name, SUM( CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 0 ELSE 1 END ) AS unhandled_service_count FROM icinga_objects AS so INNER JOIN icinga_services AS s ON s.service_object_id = so.object_id AND so.is_active = 1 INNER JOIN icinga_servicestatus AS ss ON ss.service_object_id = so.object_id AND ss.current_state > 0 INNER JOIN icinga_hoststatus AS hs ON hs.host_object_id = s.host_object_id INNER JOIN ( SELECT ho.object_id FROM icinga_objects AS ho INNER JOIN icinga_hosts AS h ON h.host_object_id = ho.object_id AND ho.is_active = 1 AND ho.objecttype_id = 1 INNER JOIN icinga_hoststatus AS hs ON hs.host_object_id = ho.object_id WHERE (CASE WHEN COALESCE(hs.current_state, 0) = 0 THEN 0 ELSE 1 END = '1') LIMIT 25 ) AS h ON h.object_id = s.host_object_id GROUP BY so.name1 HAVING (SUM( CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 0 ELSE 1 END ) > 0); -- icinga_objects icinga_services icinga_servicestatus icinga_hoststatus icinga_hosts MySQL [icinga]> SELECT so.name1 AS host_name, SUM( CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 0 ELSE 1 END ) AS unhandled_service_count -> FROM icinga_objects AS so -> INNER JOIN icinga_services AS s -> ON s.service_object_id = so.object_id -> AND so.is_active = 1 -> INNER JOIN icinga_servicestatus AS ss -> ON ss.service_object_id = so.object_id -> AND ss.current_state > 0 -> INNER JOIN icinga_hoststatus AS hs -> ON hs.host_object_id = s.host_object_id -> INNER JOIN ( -> SELECT ho.object_id -> FROM icinga_objects AS ho -> INNER JOIN icinga_hosts AS h -> ON h.host_object_id = ho.object_id -> AND ho.is_active = 1 -> AND ho.objecttype_id = 1 -> INNER JOIN icinga_hoststatus AS hs -> ON hs.host_object_id = ho.object_id -> WHERE (CASE WHEN COALESCE(hs.current_state, 0) = 0 THEN 0 ELSE 1 END = '1') LIMIT 25 -> ) AS h -> ON h.object_id = s.host_object_id -> GROUP BY so.name1 -> HAVING (SUM( CASE WHEN (ss.problem_has_been_acknowledged + ss.scheduled_downtime_depth + COALESCE(hs.current_state, 0)) > 0 THEN 0 ELSE 1 END ) > 0); ERROR 1105 (HY000): runtime error: index out of range [-1]