query-8cb690782840fa5373f9419a1a52b577
Problem getting start and end year if they exist
SELECT DISTINCT ?mandal ?mandalLabel ?startyear ?endyear WHERE {
?mandal (wdt:P31/(wdt:P279*)) wd:Q817477;
p:P131 ?districtnode.
?districtnode ps:P131 wd:Q15341.
SERVICE wikibase:label { bd:serviceParam wikibase:language "te,en". }
OPTIONAL {
?districtnode pq:P580 ?startdate.
?districtnode pq:P582 ?enddate.
}
BIND(IF(BOUND(?startdate),year(?startdate),0) as ?startyear)
BIND(IF(BOUND(?enddate),year(?enddate),0) as ?endyear)
}
ORDER BY (?mandalLabel)
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 pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Problem getting start and end year if they exist
SELECT DISTINCT ?mandal ?mandalLabel ?startyear ?endyear WHERE {
?mandal (wdt:P31/(wdt:P279*)) wd:Q817477;
p:P131 ?districtnode.
?districtnode ps:P131 wd:Q15341.
SERVICE wikibase:label { bd:serviceParam wikibase:language "te,en". }
OPTIONAL {
?districtnode pq:P580 ?startdate.
?districtnode pq:P582 ?enddate.
}
BIND(IF(BOUND(?startdate),year(?startdate),0) as ?startyear)
BIND(IF(BOUND(?enddate),year(?enddate),0) as ?endyear)
}
ORDER BY (?mandalLabel)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?districtnode")
v5("?enddate")
v7("?endyear"):::projected
v2("?mandal"):::projected
v1("?mandalLabel"):::projected
v4("?startdate")
v6("?startyear"):::projected
a1((" "))
c8(["bd:serviceParam"]):::iri
c10(["te,en"]):::literal
c6(["wd:Q15341"]):::iri
c3(["wd:Q817477"]):::iri
v2 --"p:direct/P31"--> a1
a1 --"p:direct/P279"--> c3
v2 --"p:P131"--> v3
v3 --"p:statement/P131"--> c6
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c8 --"wikibase:language"--> c10
end
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v3 -."p:qualifier/P580".-> v4
v3 --"p:qualifier/P582"--> v5
end
bind0[/"if(bound(?startdate),year-from-dateTime(?startdate),'0^^xsd:integer')"/]
v4 --o bind0
bind0 --as--o v6
bind1[/"if(bound(?enddate),year-from-dateTime(?enddate),'0^^xsd:integer')"/]
v5 --o bind1
bind1 --as--o v7