Hi Miquel,
One of our developers has attempted to craft a query for you - apparently it was pretty difficult to assemble!
The following query uses Common Table Expressions (CTE), a feature only available in MySQL 8.0 and later - so this will only work for AtoM 2.6 or later. I have not personally tested this query - while it is a select and not something that should alter your data, we still encourage you to make backups before accessing the MySQL command prompt, and proceed at your own risk!
Try the following:
WITH RECURSIVE cte AS
(
SELECT io1.id, io1.parent_id, io1.repository_id, slug.slug
FROM information_object io1
JOIN slug ON io1.repository_id=slug.object_id
UNION ALL
SELECT io2.id, io2.parent_id, io2.repository_id, cte.slug
FROM information_object io2
JOIN cte ON cte.id=io2.parent_id
AND io2.repository_id IS NULL
)
SELECT cte.slug AS institution_slug, COUNT(*) AS digital_object_count
FROM cte
JOIN digital_object ON cte.id=digital_object.object_id
JOIN object ON digital_object.id=object.id
WHERE object.created_at BETWEEN '2021-01-01' AND '2021-12-31'
GROUP BY cte.slug;
This should output something like the following:
institution_slug,digital_object_count
art-gallery-of-ontario,1
wilfrid-laurier-university-archives,25
city-of-greater-sudbury-archives,115
artefactual-archives,47
etc....
Hope that helps!