Ok so from that, i think what I have written for you is doing what you want to achieve. To go through it a bit more:
You want to start with the inner select ( i have altered this from above as you are going to need the join inside this) :
SELECT
COUNT(filteredcontact,contactid) as contactsCount,
AccountId
FROM FilteredAccount INNER JOIN
FilteredContact ON FilteredAccount.accountid = FilteredContact.accountid
GROUP BY AccountId
That gives you the count of contacts by account id
You then need to wrap that up and count how many accounts have each number of contacts
SELECT
count(accountid) as accounts
,contactsCount
FROM
— Our inner select
(SELECT
COUNT(filteredcontact,contactid) as contactsCount,
AccountId
FROM INNER JOIN
FilteredContact ON FilteredAccount.accountid = FilteredContact.accountid
GROUP BY AccountId)AS InnerSelect
GROUP BY contactsCount
that is a bit cleaner and clearer hopefully. I have made some ‘improvements’ from above so dont try and compare them too much
the a. b. stuff was just me giving the tables an alias to save writing out the name all the time (ie lazyness!)
And contactsCount is the name im giving the column that holds the contacts count per account