PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
select reduced ?x (count(distinct ?y) as ?cnt)  where
{
    ?x (rdf:type|^rdf:type) ?y
}
group by ?x
order by ?x