select count(d.id) as count from dsm_services d left outer join dsm_api a on (d.id = a.service) left outer join dsm_service_organization dso on (d.id = dso.service) left outer join dsm_organizations o on (o.id = dso.organization) where d.registrationdate >= cast(? as date) and d.eosc_datasource_type like ? and d.registrationdate < a.last_collection_date and d.registeredby is not null and d.managed = true and a.last_collection_total > 0 and a.active = true;