Q&A for science fiction and fantasy enthusiasts
DECLARE @command NVARCHAR(1024) = 'USE [?];
IF ''?'' NOT LIKE ''%meta%''
AND ''?'' <> ''StackApps''
AND EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ''CloseAsOffTopicReasonTypes'')
INSERT INTO #Counts
SELECT replace(''?'', ''StackExchange.'', ''''), count(*)
WHERE ApprovalDate is not null and DeactivationDate is null;'
CREATE TABLE #Counts (Site NVARCHAR(255), Count INT);
EXEC sp_msforeachdb @command
SELECT Site, Count
ORDER BY Count desc, Site
select Count, count(Count) as [Number of Sites]
group by Count