SELECT ?s ?count ?q ?z WHERE { { SELECT ?s ( COUNT( * ) AS ?count ) WHERE { ?s ?p ?o . } GROUP BY ?s VALUES ?s { } } ?s ?q ?z . }