query-e2772c069dad9d228f532b18dee68a2d

rq turtle/ttl

Problem to filter countries by official languageHello everyone, I'm working on a query that shows the countries where the official language is Spanish. So far I have this:

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?countryLabel ?population ((?population * 100 ) / ?suma AS ?percentage) WHERE {
  ?country wdt:P31 wd:Q6256;
           wdt:P37 ?officiallanguage ;
    wdt:P1082 ?population.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  {
    SELECT DISTINCT (SUM(?population) AS ?suma) WHERE {
      ?country wdt:P31 wd:Q6256;
               wdt:P37 ?officiallanguage ;
        wdt:P1082 ?population.
      ?officiallanguage rdfs:label ?official_language . FILTER(lang(?official_language)='es')
    }
  }
  ?officiallanguage rdfs:label ?official_language . FILTER(lang(?official_language)='es')
}
ORDER BY DESC (?percentage)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?country") v2("?official_language") v4("?officiallanguage") v7("?percentage") v5("?population"):::projected v6("?suma"):::projected c7(["bd:serviceParam"]):::iri c9(["#91;AUTO_LANGUAGE#93;,en"]):::literal c3(["wd:Q6256"]):::iri f0[["?official_language = 'es'"]] f0 --> v2 v3 --"wdt:P31"--> c3 v3 --"wdt:P37"--> v4 v3 --"wdt:P1082"--> v5 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c7 --"wikibase:language"--> c9 end f1[["?official_language = 'es'"]] f1 --> v2 v3 --"wdt:P31"--> c3 v3 --"wdt:P37"--> v4 v3 --"wdt:P1082"--> v5 v4 --"rdfs:label"--> v2 bind3[/"sum(?population)"/] v5 --o bind3 bind3 --as--o v6 v4 --"rdfs:label"--> v2 bind4[/"?population * '100^^xsd:integer' / ?suma"/] v5 --o bind4 v6 --o bind4 bind4 --as--o v7