Reputation: 11
I am writing a query in SPARQL for a knowledge graph. I have a column having Country and names of countries repeating. For example: Japan, India, US, India, India, US, US, Romania etc. and so on.
I need to write a SPARQL query that gives me the count of each country in that column. Example: Japan 1, India 3, US 3 etc. and so on.
SELECT ?countryName COUNT(?CountryName)
WHERE
{
...
}
GROUP BY ?countryName
HAVING (?countryName = "Germany")
Upvotes: 1
Views: 128
Reputation: 157
Try something like this:
SELECT ?countryName COUNT(*) AS ?count
WHERE
{ ?iri a OBJECT .
?iri rdfs:label ?countryName .
}
GROUP BY ?countryName
Keep in mind that you will need to replace OBJECT with the entity type, and I have assumed you are using the rdfs:label
predicate for the labels.
Upvotes: 2