query-c0255c1c48ebafae104322e777fc7389
List of countries and their respective capitals, currencies, populations, and flagsThis query does not return the intended information: only the current capital and flag. More than one capital and more than one flag are returned, incorrectly. Could anyone help me correct this SPARQL? Thank you so much!
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 rdfs: <http://www.w3.org/2000/01/rdf-schema#>
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_label ?capital_label ?currency_label ?population ?flag_label ?flag_image ?determination_method_label #?flag_start_time
WHERE {
?country wdt:P31 wd:Q3624078 .
FILTER NOT EXISTS {?country wdt:P31 wd:Q3024240}
FILTER NOT EXISTS {?country wdt:P31 wd:Q28171280}
OPTIONAL { ?country wdt:P36 ?capital } .
OPTIONAL {
?country p:P36 [
ps:P36 ?capital;
pq:P459 ?determination_method].
?determination_method rdfs:label ?determination_method_label .
#FILTER(STR(?determination_method_label) != "de jure")
FILTER (LANG(?determination_method_label) = "ru")
} .
OPTIONAL { ?country wdt:P38 ?currency } .
OPTIONAL { ?country wdt:P1082 ?population } .
OPTIONAL {
?country p:P41 ?flagStatement .
?flagStatement wikibase:rank wikibase:PreferredRank .
?flagStatement ps:P41 ?flag_image .
#?flagStatement pq:P580 ?flag_start_time .
} .
SERVICE wikibase:label {
?country rdfs:label ?country_label .
?capital rdfs:label ?capital_label .
?currency rdfs:label ?currency_label .
?country rdfs:label ?flag_label .
bd:serviceParam wikibase:language "en" .
}
}
ORDER BY ?country_label
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?capital")
v10("?capital_label"):::projected
v3("?country")
v1("?country_label"):::projected
v6("?currency")
v11("?currency_label"):::projected
v5("?determination_method")
v2("?determination_method_label"):::projected
v8("?flagStatement")
v9("?flag_image"):::projected
v12("?flag_label"):::projected
v7("?population"):::projected
a1((" "))
c3(["wd:Q28171280"]):::iri
c15(["wikibase:PreferredRank"]):::iri
c20(["en"]):::literal
c4(["wd:Q3024240"]):::iri
c5(["wd:Q3624078"]):::iri
c18(["bd:serviceParam"]):::iri
f0[["not "]]
subgraph f0e0["Exists Clause"]
e0v1 --"p:direct/P31"--> e0c2
e0v1("?country"):::projected
e0c2(["wd:Q28171280"]):::iri
end
f0--EXISTS--> f0e0
f0 --> v3
f0 --> c2
f0 --> c3
v3 --"p:direct/P31"--> c3
f1[["not "]]
subgraph f1e1["Exists Clause"]
e1v1 --"p:direct/P31"--> e1c2
e1v1("?country"):::projected
e1c2(["wd:Q3024240"]):::iri
end
f1--EXISTS--> f1e1
f1 --> v3
f1 --> c2
f1 --> c4
v3 --"p:direct/P31"--> c4
v3 --"p:direct/P31"--> c5
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v3 -."p:direct/P36".-> v4
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
a1 -."p:statement/P36".-> v4
a1 --"p:qualifier/P459"--> v5
v3 --"p:P36"--> a1
v5 --"rdfs:label"--> v2
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v3 -."p:direct/P38".-> v6
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v3 -."p:direct/P1082".-> v7
end
subgraph optional4["(optional)"]
style optional4 fill:#bbf,stroke-dasharray: 5 5;
v3 -."p:P41".-> v8
v8 --"wikibase:rank"--> c15
v8 --"p:statement/P41"--> v9
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
v3 --"rdfs:label"--> v1
v4 --"rdfs:label"--> v10
v6 --"rdfs:label"--> v11
v3 --"rdfs:label"--> v12
c18 --"wikibase:language"--> c20
end