query-9e7b87cdb0e6b4f8d268993abcd8ee6e

rq turtle/ttl

11:18, 30 December 2018 (UTC) Jura to p31-statements on these items, not all countries appeared. Also, to ensure you get same unit for area, I added the format in meter. --- rankI added an edited version above. As some added preferred 08:07, 31 December 2018 (UTC) JuraIt has three values. The easy fix is to comment out the line with (wdt:P2046) to avoid combining them with ?area2 they don't belong (done above). One could also use p:P2046 and map it correctly. --- 14:10, 30 December 2018 (UTC)) talk (BouzinacMINUS { ?country wdt:P582 :b3. } MINUS { ?country wdt:P576 :b2. } # remove items with P576 (dissolved, abolished or demolished) as a main property I would add the filters ; 12:16, 30 December 2018 (UTC)) talk (Strainu! I understand the first change, but I'm not sure about the second. It returns some weird results for Russia, especially if you drop the "DINSTINCT".--Jura1Thanks

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>
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 ?country ?countryLabel (ROUND(COALESCE(?area3, ?area2)/1000000) as ?area_km2) ?part ?partLabel
{
  ?country p:P31/ps:P31 wd:Q6256 .
  ?country wdt:P30 wd:Q46 .
  ?country p:P2046 / psn:P2046 [ wikibase:quantityAmount ?area2  ] .
  OPTIONAL { ?country p:P30 [ pq:P518 ?part ; ps:P30 wd:Q46 ] .
            ?part p:P2046 / psn:P2046 [ wikibase:quantityAmount ?area3  ] .
            }
  MINUS { ?country wdt:P576 [] }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER by desc(?area_km2)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?area2"):::projected v5("?area3"):::projected v6("?area_km2") v2("?country"):::projected v4("?part"):::projected a7((" ")) a1((" ")) a3((" ")) a2((" ")) a4((" ")) a6((" ")) a5((" ")) c5(["wd:Q46"]):::iri c14(["bd:serviceParam"]):::iri c16(["#91;AUTO_LANGUAGE#93;,en"]):::literal c3(["wd:Q6256"]):::iri v2 --"p:P31"--> a1 a1 --"p:statement/P31"--> c3 v2 --"p:direct/P30"--> c5 a2 --"wikibase:quantityAmount"--> v3 v2 --"p:P2046"--> a3 a3 --"p:statement/value-normalized/P2046"--> a2 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; a4 -."p:qualifier/P518".-> v4 a4 --"p:statement/P30"--> c5 v2 --"p:P30"--> a4 a5 --"wikibase:quantityAmount"--> v5 v4 --"p:P2046"--> a6 a6 --"p:statement/value-normalized/P2046"--> a5 end subgraph minus0["MINUS"] style minus0 stroke-width:6px,fill:pink,stroke:red; v2 --"p:direct/P576"--> a7 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c14 --"wikibase:language"--> c16 end bind1[/"numeric-round(?area3?area2 / '1000000^^xsd:integer')"/] v5 --o bind1 v3 --o bind1 bind1 --as--o v6