0

I'm trying to write a SPARQL query that will return a subject and the number of objects it has for a particular predicate. Here's what I have, but it is not working.

SELECT ?quote (COUNT(?quotedBy) AS ?no) WHERE {
  ?quote <http://scta.info/property/quotationType> <http://scta.info/resource/quoteType/Biblical> . 
  ?quote <http://scta.info/property/quotedBy> ?quotedBy .
} 
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Jeff
  • 3,943
  • 8
  • 45
  • 68

1 Answers1

4

Your query isn't legal. If you check at sparql.org's query validator, you'll get the response:

Syntax error:

Non-group key variable in SELECT: ?quote

You need to group by one or more variables. In this case, you want to count the number of ?quotedBy values per value of ?quote, so you'd need to group by ?quote:

select ?quote (count(?quotedBy) AS ?no) where {
  ?quote <http://scta.info/property/quotationType> <http://scta.info/resource/quoteType/Biblical> . 
  ?quote <http://scta.info/property/quotedBy> ?quotedBy .
} 
group by ?quote 
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353