query-684cf58ea1ade733ed3d0e31712e2122
added before 2016-10
TEMPLATE={"template":"Largest ?c with ?sex head of government","variables":{"?sex":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q48264 . } "},"?c":{"query":"SELECT DISTINCT ?id WHERE { ?c wdt:P31 ?id. ?c p:P6 ?mayor. }"} } }
SELECT DISTINCT ?city ?cityLabel ?mayor ?mayorLabel WHERE { BIND(wd:Q6581072 AS ?sex) BIND(wd:Q515 AS ?c)
?city wdt:P31/wdt:P279* ?c . # find instances of subclasses of city
?city p:P6 ?statement . # with a P6 (head of goverment) statement
?statement ps:P6 ?mayor . # ... that has the value ?mayor
?mayor wdt:P21 ?sex . # ... where the ?mayor has P21 (sex or gender) female
FILTER NOT EXISTS { ?statement pq:P582 ?x } # ... but the statement has no P582 (end date) qualifier
# Now select the population value of the ?city
# (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")
?city wdt:P1082 ?population .
# Optionally, find English labels for city and mayor:
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
}
} ORDER BY DESC(?population) LIMIT 10 added before 2016-10
TEMPLATE={"template":"Largest ?c with ?sex head of government","variables":{"?sex":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q48264 . } "},"?c":{"query":"SELECT DISTINCT ?id WHERE { ?c wdt:P31 ?id. ?c p:P6 ?mayor. }"} } }
SELECT DISTINCT ?city ?cityLabel ?mayor ?mayorLabel WHERE { BIND(wd:Q6581072 AS ?sex) BIND(wd:Q515 AS ?c)
?city wdt:P31/wdt:P279* ?c . # find instances of subclasses of city
?city p:P6 ?statement . # with a P6 (head of goverment) statement
?statement ps:P6 ?mayor . # ... that has the value ?mayor
?mayor wdt:P21 ?sex . # ... where the ?mayor has P21 (sex or gender) female
FILTER NOT EXISTS { ?statement pq:P582 ?x } # ... but the statement has no P582 (end date) qualifier
# Now select the population value of the ?city
# (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")
?city wdt:P1082 ?population .
# Optionally, find English labels for city and mayor:
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
}
} ORDER BY DESC(?population) LIMIT 10 added before 2016-10
TEMPLATE={"template":"Largest ?c with ?sex head of government","variables":{"?sex":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q48264 . } "},"?c":{"query":"SELECT DISTINCT ?id WHERE { ?c wdt:P31 ?id. ?c p:P6 ?mayor. }"} } }
SELECT DISTINCT ?city ?cityLabel ?mayor ?mayorLabel WHERE { BIND(wd:Q6581072 AS ?sex) BIND(wd:Q515 AS ?c)
?city wdt:P31/wdt:P279* ?c . # find instances of subclasses of city
?city p:P6 ?statement . # with a P6 (head of goverment) statement
?statement ps:P6 ?mayor . # ... that has the value ?mayor
?mayor wdt:P21 ?sex . # ... where the ?mayor has P21 (sex or gender) female
FILTER NOT EXISTS { ?statement pq:P582 ?x } # ... but the statement has no P582 (end date) qualifier
# Now select the population value of the ?city
# (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")
?city wdt:P1082 ?population .
# Optionally, find English labels for city and mayor:
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
}
} ORDER BY DESC(?population) LIMIT 10 added before 2016-10
TEMPLATE={"template":"Largest ?c with ?sex head of government","variables":{"?sex":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q48264 . } "},"?c":{"query":"SELECT DISTINCT ?id WHERE { ?c wdt:P31 ?id. ?c p:P6 ?mayor. }"} } }
SELECT DISTINCT ?city ?cityLabel ?mayor ?mayorLabel WHERE { BIND(wd:Q6581072 AS ?sex) BIND(wd:Q515 AS ?c)
?city wdt:P31/wdt:P279* ?c . # find instances of subclasses of city
?city p:P6 ?statement . # with a P6 (head of goverment) statement
?statement ps:P6 ?mayor . # ... that has the value ?mayor
?mayor wdt:P21 ?sex . # ... where the ?mayor has P21 (sex or gender) female
FILTER NOT EXISTS { ?statement pq:P582 ?x } # ... but the statement has no P582 (end date) qualifier
# Now select the population value of the ?city
# (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")
?city wdt:P1082 ?population .
# Optionally, find English labels for city and mayor:
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
}
} ORDER BY DESC(?population) LIMIT 10 added before 2016-10
TEMPLATE={"template":"Largest ?c with ?sex head of government","variables":{"?sex":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q48264 . } "},"?c":{"query":"SELECT DISTINCT ?id WHERE { ?c wdt:P31 ?id. ?c p:P6 ?mayor. }"} } }
SELECT DISTINCT ?city ?cityLabel ?mayor ?mayorLabel WHERE { BIND(wd:Q6581072 AS ?sex) BIND(wd:Q515 AS ?c)
?city wdt:P31/wdt:P279* ?c . # find instances of subclasses of city
?city p:P6 ?statement . # with a P6 (head of goverment) statement
?statement ps:P6 ?mayor . # ... that has the value ?mayor
?mayor wdt:P21 ?sex . # ... where the ?mayor has P21 (sex or gender) female
FILTER NOT EXISTS { ?statement pq:P582 ?x } # ... but the statement has no P582 (end date) qualifier
# Now select the population value of the ?city
# (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")
?city wdt:P1082 ?population .
# Optionally, find English labels for city and mayor:
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
}
} ORDER BY DESC(?population) LIMIT 10 added before 2016-10
TEMPLATE={"template":"Largest ?c with ?sex head of government","variables":{"?sex":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q48264 . } "},"?c":{"query":"SELECT DISTINCT ?id WHERE { ?c wdt:P31 ?id. ?c p:P6 ?mayor. }"} } }
SELECT DISTINCT ?city ?cityLabel ?mayor ?mayorLabel WHERE { BIND(wd:Q6581072 AS ?sex) BIND(wd:Q515 AS ?c)
?city wdt:P31/wdt:P279* ?c . # find instances of subclasses of city
?city p:P6 ?statement . # with a P6 (head of goverment) statement
?statement ps:P6 ?mayor . # ... that has the value ?mayor
?mayor wdt:P21 ?sex . # ... where the ?mayor has P21 (sex or gender) female
FILTER NOT EXISTS { ?statement pq:P582 ?x } # ... but the statement has no P582 (end date) qualifier
# Now select the population value of the ?city
# (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")
?city wdt:P1082 ?population .
# Optionally, find English labels for city and mayor:
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
}
} ORDER BY DESC(?population) LIMIT 10 added before 2016-10
TEMPLATE={"template":"Largest ?c with ?sex head of government","variables":{"?sex":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q48264 . } "},"?c":{"query":"SELECT DISTINCT ?id WHERE { ?c wdt:P31 ?id. ?c p:P6 ?mayor. }"} } }
SELECT DISTINCT ?city ?cityLabel ?mayor ?mayorLabel WHERE { BIND(wd:Q6581072 AS ?sex) BIND(wd:Q515 AS ?c)
?city wdt:P31/wdt:P279* ?c . # find instances of subclasses of city
?city p:P6 ?statement . # with a P6 (head of goverment) statement
?statement ps:P6 ?mayor . # ... that has the value ?mayor
?mayor wdt:P21 ?sex . # ... where the ?mayor has P21 (sex or gender) female
FILTER NOT EXISTS { ?statement pq:P582 ?x } # ... but the statement has no P582 (end date) qualifier
# Now select the population value of the ?city
# (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")
?city wdt:P1082 ?population .
# Optionally, find English labels for city and mayor:
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
}
} ORDER BY DESC(?population) LIMIT 10 added before 2016-10
TEMPLATE={"template":"Largest ?c with ?sex head of government","variables":{"?sex":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q48264 . } "},"?c":{"query":"SELECT DISTINCT ?id WHERE { ?c wdt:P31 ?id. ?c p:P6 ?mayor. }"} } }
SELECT DISTINCT ?city ?cityLabel ?mayor ?mayorLabel WHERE { BIND(wd:Q6581072 AS ?sex) BIND(wd:Q515 AS ?c)
?city wdt:P31/wdt:P279* ?c . # find instances of subclasses of city
?city p:P6 ?statement . # with a P6 (head of goverment) statement
?statement ps:P6 ?mayor . # ... that has the value ?mayor
?mayor wdt:P21 ?sex . # ... where the ?mayor has P21 (sex or gender) female
FILTER NOT EXISTS { ?statement pq:P582 ?x } # ... but the statement has no P582 (end date) qualifier
# Now select the population value of the ?city
# (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")
?city wdt:P1082 ?population .
# Optionally, find English labels for city and mayor:
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
}
} ORDER BY DESC(?population) LIMIT 10 added before 2016-10
TEMPLATE={"template":"Largest ?c with ?sex head of government","variables":{"?sex":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q48264 . } "},"?c":{"query":"SELECT DISTINCT ?id WHERE { ?c wdt:P31 ?id. ?c p:P6 ?mayor. }"} } }
SELECT DISTINCT ?city ?cityLabel ?mayor ?mayorLabel WHERE { BIND(wd:Q6581072 AS ?sex) BIND(wd:Q515 AS ?c)
?city wdt:P31/wdt:P279* ?c . # find instances of subclasses of city
?city p:P6 ?statement . # with a P6 (head of goverment) statement
?statement ps:P6 ?mayor . # ... that has the value ?mayor
?mayor wdt:P21 ?sex . # ... where the ?mayor has P21 (sex or gender) female
FILTER NOT EXISTS { ?statement pq:P582 ?x } # ... but the statement has no P582 (end date) qualifier
# Now select the population value of the ?city
# (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")
?city wdt:P1082 ?population .
# Optionally, find English labels for city and mayor:
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
}
} ORDER BY DESC(?population) LIMIT 10 added before 2016-10
TEMPLATE={"template":"Largest ?c with ?sex head of government","variables":{"?sex":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q48264 . } "},"?c":{"query":"SELECT DISTINCT ?id WHERE { ?c wdt:P31 ?id. ?c p:P6 ?mayor. }"} } }
SELECT DISTINCT ?city ?cityLabel ?mayor ?mayorLabel WHERE { BIND(wd:Q6581072 AS ?sex) BIND(wd:Q515 AS ?c)
?city wdt:P31/wdt:P279* ?c . # find instances of subclasses of city
?city p:P6 ?statement . # with a P6 (head of goverment) statement
?statement ps:P6 ?mayor . # ... that has the value ?mayor
?mayor wdt:P21 ?sex . # ... where the ?mayor has P21 (sex or gender) female
FILTER NOT EXISTS { ?statement pq:P582 ?x } # ... but the statement has no P582 (end date) qualifier
# Now select the population value of the ?city
# (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")
?city wdt:P1082 ?population .
# Optionally, find English labels for city and mayor:
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
}
} ORDER BY DESC(?population) LIMIT 10
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#>
#added before 2016-10
#TEMPLATE={"template":"Largest ?c with ?sex head of government","variables":{"?sex":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q48264 . } "},"?c":{"query":"SELECT DISTINCT ?id WHERE { ?c wdt:P31 ?id. ?c p:P6 ?mayor. }"} } }
SELECT DISTINCT ?city ?cityLabel ?mayor ?mayorLabel
WHERE
{
BIND(wd:Q6581072 AS ?sex)
BIND(wd:Q515 AS ?c)
?city wdt:P31/wdt:P279* ?c . # find instances of subclasses of city
?city p:P6 ?statement . # with a P6 (head of goverment) statement
?statement ps:P6 ?mayor . # ... that has the value ?mayor
?mayor wdt:P21 ?sex . # ... where the ?mayor has P21 (sex or gender) female
FILTER NOT EXISTS { ?statement pq:P582 ?x } # ... but the statement has no P582 (end date) qualifier
# Now select the population value of the ?city
# (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")
?city wdt:P1082 ?population .
# Optionally, find English labels for city and mayor:
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
}
}
ORDER BY DESC(?population)
LIMIT 10
Query found at
- https://www.wikidata.org/wiki/User:Duesentrieb/WDQL
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/en
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/es
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/fr
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/hy
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/ja
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/nl
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/sv
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/tr
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/uk
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples/advanced/zh