query-4011e4a920add4a4e077760c05517632
List of Indian states with their chief ministers and their ages SELECT ?state ?stateLabel ?leader ?leaderLabel ?birthdate ?age WHERE { ?state wdt:P31 wd:Q13390680. ?state wdt:P6 ?leader. OPTIONAL { ?leader wdt:P569 ?birthdate. BIND(YEAR(NOW()) - YEAR(?birthdate) - IF(MONTH(NOW()) < MONTH(?birthdate) || (MONTH(NOW()) = MONTH(?birthdate) && DAY(NOW()) < DAY(?birthdate)), 1, 0) AS ?age) . } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY ?stateLabel ?leaderLabel
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 bd: <http://www.bigdata.com/rdf#>
# List of Indian states with their chief ministers and their ages
SELECT ?state ?stateLabel ?leader ?leaderLabel ?birthdate ?age
WHERE {
?state wdt:P31 wd:Q13390680.
?state wdt:P6 ?leader.
OPTIONAL {
?leader wdt:P569 ?birthdate.
BIND(YEAR(NOW()) - YEAR(?birthdate) - IF(MONTH(NOW()) < MONTH(?birthdate) || (MONTH(NOW()) = MONTH(?birthdate) && DAY(NOW()) < DAY(?birthdate)), 1, 0) AS ?age) .
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?stateLabel ?leaderLabel
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v6("?age"):::projected
v5("?birthdate"):::projected
v4("?leader"):::projected
v2("?leaderLabel"):::projected
v3("?state"):::projected
v1("?stateLabel"):::projected
c6(["bd:serviceParam"]):::iri
c2(["wd:Q13390680"]):::iri
c8(["#91;AUTO_LANGUAGE#93;,en"]):::literal
v3 --"wdt:P31"--> c2
v3 --"wdt:P6"--> v4
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v4 -."wdt:P569".-> v5
bind0[/"year-from-dateTime(NOW()) - year-from-dateTime(?birthdate) - if((month-from-dateTime(NOW()) < month-from-dateTime(?birthdate) || month-from-dateTime(NOW()) = month-from-dateTime(?birthdate)day-from-dateTime(NOW()) < day-from-dateTime(?birthdate)),'1^^xsd:integer','0^^xsd:integer')"/]
v5 --o bind0
bind0 --as--o v6
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c6 --"wikibase:language"--> c8
end