PREFIX rdf: SELECT (SUM(?val) AS ?sum) (COUNT(?a) AS ?count) (COUNT(*) AS ?countAll) WHERE { ?a rdf:value ?val . } GROUP BY ?a