This seems to work:
SELECT c.avatar, COUNT(m.referenceid) AS numConnections, c.user_id, u.id, u.username FROM #__comprofiler AS c, #__users AS u, #__comprofiler_members AS m WHERE (c.user_id = u.id) AND (c.user_id = m.referenceid) AND c.banned='0' and m.accepted='1' GROUP BY m.referenceid ORDER BY numConnections DESC
There's a nuance, however. On the Connections Tab in the CB Admin backend, there's an option for allowing cross connections. In other words, some connections are one way, and others are two way.
I'm not sure whether this query can distinguish between the two types, or even whether it should. The problem would lie with separating out the one-way connections. If you have your configuration set to allow cross-connections, then I think this is the answer.
Raj