PREFIX foaf: SELECT ?name (COUNT(?friend) AS ?count) WHERE { ?person foaf:name ?name . ?person foaf:knows ?friend . } GROUP BY ?person ?name