You're counting the same thing you're grouping by. I think you need:
SELECT ?c (COUNT(DISTINCT ?p) AS ?pcount)
WHERE {
?s a ?c .
?s ?p ?o .
}
GROUP BY ?c
http://sparql.org/sparql?query=++++SELECT+%3Fc+%28COUNT%28DISTINCT+%3Fp%29+AS+%3Fpcount%29%0D%0A++++WHERE+%7B%0D%0A+++++++%3Fs+a+%3Fc+.%0D%0A+++++++%3Fs+%3Fp+%3Fo+.%0D%0A++++%7D%0D%0A++++GROUP+BY+%3Fc&default-graph-uri=http%3A%2F%2Fwww.snee.com%2Fbobdc.blog%2Ffiles%2FBeatlesMusicians.ttl&output=text&stylesheet=%2Fxml-to-html.xsl
On Tue, Jan 25, 2022 at 12:05 AM Bob DuCharme <[email protected]> wrote:
>
> Using arq and the data at
> http://www.snee.com/bobdc.blog/files/BeatlesMusicians.ttl, I’m trying to
> write a query that will list the classes used in the data and the number
> of distinct properties used by instances of that class. I’m having a
> hard time and can’t even write a query that lists the number of
> properties used for just one of the classes; the following just shows me
> a series of ones.
>
> SELECT (COUNT(DISTINCT ?p) AS ?pcount)
> WHERE {
> ?s a <http://learningsparql.com/ns/schema/Song> .
> ?s ?p ?o .
> }
> GROUP BY ?p
>
> Any suggestions?
>
> Thanks,
>
> Bob
>