query-3e0e69f9dd2da709fb512f4f2ced4ccc

rq turtle/ttl

National flags sorted by number of colours

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#>
# colorful state flags
#defaultView:ImageGrid
SELECT ?state ?stateLabel (COUNT(?color) AS ?count) ?image WHERE {
   {
  SELECT DISTINCT ?state WHERE {
    ?state wdt:P31/wdt:P279* wd:Q3624078;
           p:P463 ?memberOfStatement.
    ?memberOfStatement a wikibase:BestRank;
                         ps:P463 wd:Q1065.
    MINUS { ?memberOfStatement pq:P582 ?endTime. }
    MINUS { ?state wdt:P576|wdt:P582 ?end. }
  }
}
  ?state wdt:P163 ?flag.
  ?flag wdt:P462 ?color.
  OPTIONAL { ?flag wdt:P18 ?image. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?state ?stateLabel ?image
ORDER BY DESC(?count)
LIMIT 25

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v7("?color"):::projected v9("?count") v5("?end") v4("?endTime") v6("?flag") v8("?image"):::projected v3("?memberOfStatement") v2("?state"):::projected a1((" ")) c6(["wikibase:BestRank"]):::iri c3(["wd:Q3624078"]):::iri c16(["bd:serviceParam"]):::iri c8(["wd:Q1065"]):::iri c18(["#91;AUTO_LANGUAGE#93;,en"]):::literal v2 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c3 v2 --"p:P463"--> v3 v3 --"a"--> c6 v3 --"p:statement/P463"--> c8 subgraph minus0["MINUS"] style minus0 stroke-width:6px,fill:pink,stroke:red; v3 --"p:qualifier/P582"--> v4 end subgraph minus1["MINUS"] style minus1 stroke-width:6px,fill:pink,stroke:red; subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v2 --"p:direct/P582"--> v5 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v2 --"p:direct/P576"--> v5 end union0r <== or ==> union0l end end v2 --"p:direct/P163"--> v6 v6 --"p:direct/P462"--> v7 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:direct/P18".-> v8 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c16 --"wikibase:language"--> c18 end bind3[/"count(?color)"/] v7 --o bind3 bind3 --as--o v9