query-b5d9c83ef726d6e96c366bfb2f619ace

rq turtle/ttl

PropertiesINSEE municipality code (P374)population (P1082)instance of (P31)end time (P582)

Use at

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 ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
SELECT DISTINCT ?commune ?commune_label ?insee (COUNT(?population) AS ?nb)
WHERE {
  ?commune p:P31 ?communeStatement .
  { ?communeStatement ps:P31 wd:Q484170 . } UNION 
  { ?communeStatement ps:P31 wd:Q2989454 . }

  OPTIONAL { ?commune rdfs:label ?commune_label FILTER (LANG(?commune_label) = "fr") . }
  FILTER NOT EXISTS { ?communeStatement pq:P582 ?dateFin . }

  ?commune wdt:P374 ?insee .

  OPTIONAL { ?commune wdt:P1082 ?population . }
} GROUP BY ?commune ?commune_label ?insee HAVING ( ?nb >= 2 ) ORDER BY ?commune

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v1("?commune"):::projected v3("?communeStatement") v5("?commune_label"):::projected v4("?dateFin") v6("?insee"):::projected v8("?nb") v7("?population"):::projected c7(["wd:Q2989454"]):::iri c6(["wd:Q484170"]):::iri f0[["?nb >= '2^^xsd:integer'"]] f0 --> v8 f1[["not "]] subgraph f1e0["Exists Clause"] e0v1 --"p:qualifier/P582"--> e0v2 e0v1("?communeStatement"):::projected e0v2("?dateFin"):::projected end f1--EXISTS--> f1e0 f1 --> v3 f1 --> c2 f1 --> v4 v3 --"p:qualifier/P582"--> v4 v1 --"p:P31"--> v3 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v3 --"p:statement/P31"--> c7 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v3 --"p:statement/P31"--> c6 end union0r <== or ==> union0l end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v1 -."rdfs:label".-> v5 end v1 --"p:direct/P374"--> v6 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P1082".-> v7 end bind3[/"count(?population)"/] v7 --o bind3 bind3 --as--o v8