SELECT Count( DISTINCT res.id_ ) FROM ACT_RU_TASK res inner join ACT_RU_IDENTITYLINK i ON i.task_id_ = res.id_ left join ACT_RE_PROCDEF procdef ON res.proc_def_id_ = procdef.id_ left join ( SELECT a.* FROM ACT_RU_AUTHORIZATION a WHERE ... ) auth ON ( auth.resource_id_ IN ( res.id_, procdef.key_, '*' ) ) WHERE res.assignee_ IS NULL AND res.assignee_ IS NULL AND i.type_ = 'candidate' AND ( i.group_id_ IN ( 'accounting', 'camunda-admin', 'management', 'sales' ) ) AND res.suspension_state_ = 1 AND ( ( res.case_execution_id_ IS NOT NULL ) OR ( auth.resource_id_ IS NOT NULL ) );