I am using WikiData SPARQL Endpoint to search for two entities: museums (wd:Q33506
) and libraries (wd:Q7075
) that have instagram and twitter accounts and from which country they are from. I am trying to count them and group them by country.
SELECT ?item ?instagram ?twitter ?countryLabel (COUNT(?country) AS ?ccount) WHERE {
{ ?item (wdt:P31/wdt:P279*) wd:Q33506. }
{ ?item (wdt:P31/wdt:P279*) wd:Q7075. }
?item wdt:P2003 ?instagram.
?item wdt:P2002 ?twitter.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
OPTIONAL { ?item wdt:P17 ?country. }
}
GROUP BY ?country
ORDER BY ?ccount