query-202f3eec37bf7f7e1d7fa47580e37cd6
Conditional sum fail 19:38, 29 June 2018 (UTC)) talk (TagishsimonThis is a report on number of crew-members for space-shuttle missions ... the variable ?applies indicates if the crew member was aboard only for launch, or only for takeoff. So I'm wanting to count where ?applies="wd:Q854248" and where ?applies="wd:Q844947" ... and right now failing to do that. Might I have a steer, please; thanks --
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 pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?item ?itemLabel ?launch (count(?tom) as ?crew) (sum(if(!bound(?applies),1,0)) as ?both_ways) (sum(if(?applies=wd:Q854248,1,0)) as ?up_only) (sum(if(?applies=wd:Q844947,1,0)) as ?down_only)
WHERE
{
values ?item {wd:Q384250} .
?item wdt:P31 wd:Q752783.
?item wdt:P361 wd:Q1775296.
optional {?item p:P1029 ?tom.
optional {?tom pq:P518 ?applies. } }
optional {?item wdt:P619 ?launch.}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} group by ?item ?itemLabel ?launch
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?applies"):::projected
v6("?both_ways")
v5("?crew")
v8("?down_only")
v1("?item"):::projected
v4("?launch"):::projected
v2("?tom"):::projected
v7("?up_only")
c4(["wd:Q1775296"]):::iri
c2(["wd:Q752783"]):::iri
c9(["bd:serviceParam"]):::iri
c11(["#91;AUTO_LANGUAGE#93;,en"]):::literal
bind0[/VALUES ?item/]
bind0-->v1
bind00(["wd:Q384250"])
bind00 --> bind0
v1 --"p:direct/P31"--> c2
v1 --"p:direct/P361"--> c4
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."p:P1029".-> v2
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v2 -."p:qualifier/P518".-> v3
end
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v1 -."p:direct/P619".-> v4
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c9 --"wikibase:language"--> c11
end
bind5[/"count(?tom)"/]
v2 --o bind5
bind5 --as--o v5
bind6[/"sum(if(not bound(?applies),'1^^xsd:integer','0^^xsd:integer'))"/]
v3 --o bind6
bind6 --as--o v6
bind7[/"sum(if(?applies = 'wd:Q854248','1^^xsd:integer','0^^xsd:integer'))"/]
v3 --o bind7
bind7 --as--o v7
bind8[/"sum(if(?applies = 'wd:Q844947','1^^xsd:integer','0^^xsd:integer'))"/]
v3 --o bind8
bind8 --as--o v8