query-90c6b6d131447d39fde49ff1f3f7c3dc

rq turtle/ttl

The following query uses these:  female (Q6581072),  city (Q515): Items  end time (P582),  head of government (P6),  population (P1082),  sex or gender (P21),  subclass of (P279),  instance of (P31): Properties

Use at

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 DISTINCT ?city ?cityLabel ?mayor ?mayorLabel 
WHERE 
{
    ?city wdt:P31/wdt:P279* wd:Q515 .  # 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 wd:Q6581072 .       # ... 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 "en" .
    }
}
ORDER BY DESC(?population)
LIMIT 10

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?city"):::projected v5("?mayor"):::projected v1("?population") v2("?statement") v3("?x") a1((" ")) c13(["en"]):::literal c8(["wd:Q6581072"]):::iri c11(["bd:serviceParam"]):::iri c4(["wd:Q515"]):::iri f0[["not "]] subgraph f0e0["Exists Clause"] e0v1 --"p:qualifier/P582"--> e0v2 e0v1("?statement"):::projected e0v2("?x"):::projected end f0--EXISTS--> f0e0 f0 --> v2 f0 --> c1 f0 --> v3 v2 --"p:qualifier/P582"--> v3 v4 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c4 v4 --"p:P6"--> v2 v2 --"p:statement/P6"--> v5 v5 --"p:direct/P21"--> c8 v4 --"p:direct/P1082"--> v1 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c11 --"wikibase:language"--> c13 end