query-ba95d1c5cd2ab16cbc54c4ccbf7852b5

rq turtle/ttl

TODO

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
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 ?item ?itemLabel (sum(?number) as ?count)
WHERE 
{
#  VALUES ?instrument {wd:Q5994} # count only the number of pianos
  VALUES ?item {wd:Q831870 wd:Q3414614 wd:Q2352641 wd:Q3053508 }
  ?item p:P870 ?stat.
  ?stat ps:P870 ?instrument .
#  FILTER (?instrument NOT IN (wd:Q8355)) # exclude violins from the count
  OPTIONAL {?stat pq:P1132 ?no1.}
  OPTIONAL {?stat pq:P1114 ?no2.}
  BIND(COALESCE(?no2,?no1,1) as ?number)
#  FILTER NOT EXISTS {?item wdt:P870 wd:Q8355} # exclude music having a violin
#  FILTER EXISTS {?item wdt:P870 wd:Q8355} # include music only is it has a violin

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} group by ?item ?itemLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v7("?count") v3("?instrument") v1("?item"):::projected v4("?no1") v5("?no2") v6("?number"):::projected v2("?stat") c6(["bd:serviceParam"]):::iri c8(["#91;AUTO_LANGUAGE#93;,en"]):::literal bind0[/VALUES ?item/] bind0-->v1 bind00(["wd:Q831870"]) bind00 --> bind0 bind01(["wd:Q3414614"]) bind01 --> bind0 bind02(["wd:Q2352641"]) bind02 --> bind0 bind03(["wd:Q3053508"]) bind03 --> bind0 v1 --"p:P870"--> v2 v2 --"p:statement/P870"--> v3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:qualifier/P1132".-> v4 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:qualifier/P1114".-> v5 end bind1[/"?no2?no1'1^^xsd:integer'"/] v5 --o bind1 v4 --o bind1 bind1 --as--o v6 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c6 --"wikibase:language"--> c8 end bind3[/"sum(?number)"/] v6 --o bind3 bind3 --as--o v7