query-77e4a65334d287a7aecb3755ee683fdc

rq turtle/ttl

Toutes les villes du Québec

SELECT DISTINCT ?city ?cityLabel ?cityPopulation WHERE { ?city wdt:P31/wdt:P279* wd:Q3788231 . # find instances of subclasses of city # Ville du Québec OPTIONAL { ?city wdt:P3856 ?idQC } FILTER(# code géographique des municipalités du Québec BOUND(?idQC)
)

# Now select the population value of the ?city
# (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")

?city p:P1082 ?populationStatement . ?populationStatement ps:P1082 ?cityPopulation. ?populationStatement pq:P585 ?date FILTER NOT EXISTS { ?city p:P1082/pq:P585 ?date_ . FILTER (?date_ > ?date) }

# Optionally, find English labels for city and mayor:
SERVICE wikibase:label {
    bd:serviceParam wikibase:language "fr" .
}

} ORDER BY DESC(?cityPopulation)

LIMIT 200

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Toutes les villes du Québec

SELECT DISTINCT ?city ?cityLabel ?cityPopulation
WHERE
{
    ?city wdt:P31/wdt:P279* wd:Q3788231 .  # find instances of subclasses of city
    # Ville du Québec
    OPTIONAL { ?city wdt:P3856 ?idQC }
     FILTER(# code géographique des municipalités du Québec
      BOUND(?idQC)    
     )

    # Now select the population value of the ?city
    # (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")
   ?city p:P1082 ?populationStatement .
   ?populationStatement ps:P1082 ?cityPopulation.
   ?populationStatement pq:P585 ?date
   FILTER NOT EXISTS { ?city p:P1082/pq:P585 ?date_ . FILTER (?date_ > ?date) } 

    # Optionally, find English labels for city and mayor:
    SERVICE wikibase:label {
        bd:serviceParam wikibase:language "fr" .
    }
}
ORDER BY DESC(?cityPopulation)
#LIMIT 200

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?city"):::projected v1("?cityPopulation"):::projected v3("?date") v2("?date_") v5("?idQC") v6("?populationStatement") a2((" ")) a1((" ")) c9(["bd:serviceParam"]):::iri c5(["wd:Q3788231"]):::iri c11(["fr"]):::literal f0[["not "]] subgraph f0e0["Exists Clause"] e0f0[["?date_ > ?date"]] e0f0 --> e0v1 e0f0 --> e0v2 e0v3 --"p:P1082"--> e0a1 e0a1 --"p:qualifier/P585"--> e0v1 e0v3("?city"):::projected e0v2("?date"):::projected e0v1("?date_"):::projected e0a1((" ")):::projected end f0--EXISTS--> f0e0 f0 --> v2 f0 --> v3 f0 --> v4 f0 --> c1 f0 --> a1 f0 --> c2 f1[["?date_ > ?date"]] f1 --> v2 f1 --> v3 v4 --"p:P1082"--> a1 a1 --"p:qualifier/P585"--> v2 f2[["bound(?idQC)"]] f2 --> v5 v4 --"p:direct/P31"--> a2 a2 --"p:direct/P279"--> c5 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P3856".-> v5 end v4 --"p:P1082"--> v6 v6 --"p:statement/P1082"--> v1 v6 --"p:qualifier/P585"--> v3 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c9 --"wikibase:language"--> c11 end