query-7ab20b2cf39a902472fd678b01ea77c3
Filter double months 19:17, 16 June 2019 (UTC)) talk (BouzinacHello, this query looks to work fine but causes problem in very rare cases : Amsterdam (AMS) has been monthly-updated in 2018 with 2 different sources. So if there is month data, pick and sum only 12 months (not all the months ==> 2018 looks to have been sum of 12 + 12 months). How to filter the twelve month properly? Many thanks,
Use at
- https://query.wikidata.org/sparql
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 pqv: <http://www.wikidata.org/prop/qualifier/value/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?item ?itemLabel (max(?number) as ?passengers)
?year
where {
{
select ?item ?year (sum(?numberperperiod) as ?number) {
{
select ?item ?statement ?year ?timevalue ?numberperperiod{
?item wdt:P238 ?IATA
VALUES ?IATA {"AMS"}.
?item p:P3872 ?statement.
?statement pqv:P585 ?timevalue
; ps:P3872 ?numberperperiod.
?timevalue wikibase:timeValue ?date .
optional { ?statement pq:P518 ?applies .}
filter(bound(?applies)=false || ?applies = wd:Q2165236 )
bind(if(bound(?applies)=false,"no applies","everywhere") as ?where )
MINUS { ?statement wikibase:rank wikibase:DeprecatedRank }
bind (YEAR(?date) AS ?year)
FILTER (?year >1949).
FILTER (?year < year(now())).
}
}.
?timevalue wikibase:timePrecision ?prec filter ( ?prec > 9 )
} group by ?item ?year
} union {
?timevalue wikibase:timePrecision 9 .
bind (?numberperperiod as ?number)
{
select ?item ?statement ?year ?timevalue ?numberperperiod{
?item wdt:P238 ?IATA
VALUES ?IATA {"AMS"}.
?item p:P3872 ?statement.
?statement pqv:P585 ?timevalue
; ps:P3872 ?numberperperiod.
?timevalue wikibase:timeValue ?date .
optional { ?statement pq:P518 ?applies .}
filter(bound(?applies)=false || ?applies = wd:Q2165236 )
bind(if(bound(?applies)=false,"no applies","everywhere") as ?where )
MINUS { ?statement wikibase:rank wikibase:DeprecatedRank }
bind (YEAR(?date) AS ?year)
FILTER (?year >1949).
FILTER (?year < year(now())).
}
} } .
SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
} group by ?item ?itemLabel ?year
order by ?item desc (?year)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v12("?IATA")
v4("?applies")
v9("?date")
v1("?item"):::projected
v12("?number"):::projected
v8("?numberperperiod")
v12("?passengers")
v3("?prec")
v6("?statement")
v7("?timevalue")
v12("?where")
v12("?year"):::projected
c12(["wikibase:DeprecatedRank"]):::iri
c17(["fr"]):::literal
c15(["bd:serviceParam"]):::iri
c1(["9^^xsd:integer"]):::literal
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v7 --"wikibase:timePrecision"--> c1
bind0[/"?numberperperiod"/]
v8 --o bind0
bind0 --as--o v12
f1[["?year < year-from-dateTime(NOW())"]]
f1 --> v12
f2[["?year > '1949^^xsd:integer'"]]
f2 --> v12
f3[["(bound(?applies) = 'false^^xsd:boolean' || ?applies = 'wd:Q2165236')"]]
f3 --> v4
v1 --"p:direct/P238"--> v12
bind4[/VALUES ?IATA/]
bind4-->v12
bind40(["AMS"])
bind40 --> bind4
v1 --"p:P3872"--> v6
v6 --"p:qualifier/value/P585"--> v7
v6 --"p:statement/P3872"--> v8
v7 --"wikibase:timeValue"--> v9
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v6 -."p:qualifier/P518".-> v4
end
bind5[/"if(bound(?applies) = 'false^^xsd:boolean','no applies','everywhere')"/]
v4 --o bind5
bind5 --as--o v12
subgraph minus6["MINUS"]
style minus6 stroke-width:6px,fill:pink,stroke:red;
v6 --"wikibase:rank"--> c12
end
bind7[/"year-from-dateTime(?date)"/]
v9 --o bind7
bind7 --as--o v12
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
f8[["?prec > '9^^xsd:integer'"]]
f8 --> v3
f9[["?year < year-from-dateTime(NOW())"]]
f9 --> v12
f10[["?year > '1949^^xsd:integer'"]]
f10 --> v12
f11[["(bound(?applies) = 'false^^xsd:boolean' || ?applies = 'wd:Q2165236')"]]
f11 --> v4
v1 --"p:direct/P238"--> v12
bind12[/VALUES ?IATA/]
bind12-->v12
bind120(["AMS"])
bind120 --> bind12
v1 --"p:P3872"--> v6
v6 --"p:qualifier/value/P585"--> v7
v6 --"p:statement/P3872"--> v8
v7 --"wikibase:timeValue"--> v9
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v6 -."p:qualifier/P518".-> v4
end
bind13[/"if(bound(?applies) = 'false^^xsd:boolean','no applies','everywhere')"/]
v4 --o bind13
bind13 --as--o v12
subgraph minus14["MINUS"]
style minus14 stroke-width:6px,fill:pink,stroke:red;
v6 --"wikibase:rank"--> c12
end
bind15[/"year-from-dateTime(?date)"/]
v9 --o bind15
bind15 --as--o v12
v7 --"wikibase:timePrecision"--> v3
bind17[/"sum(?numberperperiod)"/]
v8 --o bind17
bind17 --as--o v12
end
union0r <== or ==> union0l
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c15 --"wikibase:language"--> c17
end
bind19[/"max(?number)"/]
v12 --o bind19
bind19 --as--o v12