query-eaf96d6b4ee09a4bcb4ffe0306c16939
Items in the UK with more than one wdt:P131
SELECT ?item ?itemLabel ?adm1 ?adm1Label ?adm2 ?adm2Label WHERE {
hint:Query hint:optimizer "None" .
{
SELECT ?item WHERE {
?item wdt:P31/wdt:P279* wd:Q171634 .
?item wdt:P17 wd:Q145 .
?item wdt:P131 ?adm .
} GROUP BY ?item
HAVING (COUNT(?adm) = 2)
}
?item wdt:P131 ?adm1 .
?item wdt:P131 ?adm2 .
?adm1 wdt:P131+ ?adm2 .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
ORDER BY ?itemLabel
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 bd: <http://www.bigdata.com/rdf#>
# Items in the UK with more than one wdt:P131
SELECT ?item ?itemLabel ?adm1 ?adm1Label ?adm2 ?adm2Label WHERE {
# hint:Query hint:optimizer "None" .
{
SELECT ?item WHERE {
?item wdt:P31/wdt:P279* wd:Q171634 .
?item wdt:P17 wd:Q145 .
?item wdt:P131 ?adm .
} GROUP BY ?item
HAVING (COUNT(?adm) = 2)
}
?item wdt:P131 ?adm1 .
?item wdt:P131 ?adm2 .
?adm1 wdt:P131+ ?adm2 .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
ORDER BY ?itemLabel
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?_anon_42b5416610844a34809f33a099ae9de171232")
v3("?adm")
v5("?adm1"):::projected
v6("?adm2"):::projected
v2("?item"):::projected
v1("?itemLabel"):::projected
a2((" "))
a1((" "))
c9(["bd:serviceParam"]):::iri
c11(["en"]):::literal
c4(["wd:Q171634"]):::iri
c6(["wd:Q145"]):::iri
f0[[" = '2^^xsd:integer'"]]
f0 --> a1
v2 --"wdt:P31"--> a2
a2 --"wdt:P279"--> c4
v2 --"wdt:P17"--> c6
v2 --"wdt:P131"--> v3
bind2[/"count(?adm)"/]
v3 --o bind2
bind2 --as--o v4
v2 --"wdt:P131"--> v5
v2 --"wdt:P131"--> v6
v5 --"wdt:P131"--> v6
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c9 --"wikibase:language"--> c11
end