query-2e731fd6ba3ff94454bf2c4e57211243
Tagishsimon
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 bd: <http://www.bigdata.com/rdf#>
SELECT ?item ?itemLabel
(SAMPLE(?ms1_) AS ?ms1) (SAMPLE(?ms1_Label) AS ?ms1Label)
(SAMPLE(?ms2_) AS ?ms2) (SAMPLE(?ms2_Label) AS ?ms2Label)
(SAMPLE(?ms3_) AS ?ms3) (SAMPLE(?ms3_Label) AS ?ms3Label)
WHERE
{
OPTIONAL {
{
SELECT ?item ?ms (COUNT(?lt) AS ?number)
WHERE
{
VALUES ?item {
wd:Q99536927 # 3 P921s
wd:Q99689936 # 2 P921s
wd:Q99927619 # 1 P921
wd:Q100144327 # 0 P921s
}
OPTIONAL
{
?item wdt:P921 ?ms .
?item wdt:P921 ?lt .
FILTER (STR(?lt) <= STR(?ms))
}
}
GROUP by ?item ?ms
}
}
BIND (IF (?number = 1, ?ms, ?unbound) AS ?ms1_)
BIND (IF (?number = 2, ?ms, ?unbound) AS ?ms2_)
BIND (IF (?number = 3, ?ms, ?unbound) AS ?ms3_)
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
?item rdfs:label ?itemLabel .
?ms1_ rdfs:label ?ms1_Label .
?ms2_ rdfs:label ?ms2_Label .
?ms3_ rdfs:label ?ms3_Label .
}
}
GROUP BY ?item ?itemLabel
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?item"):::projected
v8("?itemLabel"):::projected
v1("?lt")
v2("?ms")
v12("?ms1")
v13("?ms1Label")
v5("?ms1_"):::projected
v9("?ms1_Label"):::projected
v14("?ms2")
v15("?ms2Label")
v6("?ms2_"):::projected
v10("?ms2_Label"):::projected
v16("?ms3")
v17("?ms3Label")
v7("?ms3_"):::projected
v11("?ms3_Label"):::projected
v4("?number")
c3(["bd:serviceParam"]):::iri
c5(["en"]):::literal
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
bind0[/VALUES ?item/]
bind0-->v3
bind00(["wd:Q99536927"])
bind00 --> bind0
bind01(["wd:Q99689936"])
bind01 --> bind0
bind02(["wd:Q99927619"])
bind02 --> bind0
bind03(["wd:Q100144327"])
bind03 --> bind0
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v3 -."wdt:P921".-> v2
v3 --"wdt:P921"--> v1
end
bind2[/"count(?lt)"/]
v1 --o bind2
bind2 --as--o v4
end
bind3[/"if(?number = '1^^xsd:integer',?ms,?unbound)"/]
v4 --o bind3
v2 --o bind3
null --o bind3
bind3 --as--o v5
bind4[/"if(?number = '2^^xsd:integer',?ms,?unbound)"/]
v4 --o bind4
v2 --o bind4
null --o bind4
bind4 --as--o v6
bind5[/"if(?number = '3^^xsd:integer',?ms,?unbound)"/]
v4 --o bind5
v2 --o bind5
null --o bind5
bind5 --as--o v7
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c3 --"wikibase:language"--> c5
v3 --"rdfs:label"--> v8
v5 --"rdfs:label"--> v9
v6 --"rdfs:label"--> v10
v7 --"rdfs:label"--> v11
end
bind12[/"sample(?ms1_)"/]
v5 --o bind12
bind12 --as--o v12
bind13[/"sample(?ms1_Label)"/]
v9 --o bind13
bind13 --as--o v13
bind14[/"sample(?ms2_)"/]
v6 --o bind14
bind14 --as--o v14
bind15[/"sample(?ms2_Label)"/]
v10 --o bind15
bind15 --as--o v15
bind16[/"sample(?ms3_)"/]
v7 --o bind16
bind16 --as--o v16
bind17[/"sample(?ms3_Label)"/]
v11 --o bind17
bind17 --as--o v17