query-72963ae72aa2eb2c6ff8f0ad3170dc74

rq turtle/ttl

03:14, 30 January 2020 (UTC)) talk (Dipsacus fullonumBelow is a version year 2000. It will not show a population if none exist for the year, and it will have more than one row for the year if there is more than one population number for the year. Note that the year is used in strings 3 times in the query: 1 time as "2000", 1 time as "2000-01-01" and 1 time as "2001-01-01". I made the filter so the airport is required to have been open all of year, so if the airport is opened or closed in the year, it is not counted. I am not sure that I have (all) the right properties for opening/closing. --

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
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#>
SELECT ?country ?countryLabel ?no_of_airports ?population
WHERE
{
  {
    SELECT ?country (COUNT(?airport) AS ?no_of_airports)
    WHERE
    {
      ?airport wdt:P17 ?country.
      ?airport wdt:P31/wdt:P279* wd:Q1248784.
      OPTIONAL { ?airport wdt:P580|wdt:P571 ?starttime. }
      OPTIONAL { ?airport wdt:P582|wdt:P576 ?endtime. }
      FILTER((! BOUND(?endtime) || ?endtime >= "2001-01-01"^^xsd:dat) &&
             (! BOUND(?starttime) || ?starttime < "2000-01-01"^^xsd:dat))
    }
    GROUP BY ?country
  }
  OPTIONAL
  {
    ?country p:P1082 [
              ps:P1082 ?population;
              pq:P585 ?population_time
            ].
    FILTER(SUBSTR(STR(?population_time),1,4) = "2000")
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?airport") v5("?country"):::projected v2("?endtime") v6("?no_of_airports"):::projected v7("?population"):::projected v1("?population_time") v3("?starttime") a1((" ")) a2((" ")) c9(["wd:Q1248784"]):::iri c18(["bd:serviceParam"]):::iri c20(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["(not bound(?endtime) || ?endtime >= s2001-01-01^^<http://www.w3.org/2001/XMLSchema#dat>')(not bound(?starttime) || ?starttime < s2000-01-01^^<http://www.w3.org/2001/XMLSchema#dat>')"]] f0 --> v2 f0 --> v3 v4 --"p:direct/P17"--> v5 v4 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c9 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v4 -."p:direct/P571".-> v3 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v4 --"p:direct/P580"--> v3 end union0r <== or ==> union0l end end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; v4 -."p:direct/P576".-> v2 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v4 --"p:direct/P582"--> v2 end union1r <== or ==> union1l end end bind2[/"count(?airport)"/] v4 --o bind2 bind2 --as--o v6 subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; a2 -."p:statement/P1082".-> v7 a2 --"p:qualifier/P585"--> v1 v5 --"p:P1082"--> a2 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c18 --"wikibase:language"--> c20 end