query-c2c8a9e8347b70d94750baef3bc4b9d6
Count gender in a listI've made this query to list how many songs or hymns are published in each songbook:
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 ?songbook ?name (COUNT(?song) AS ?songs) WHERE {
{ ?song wdt:P31 wd:Q7366. }
UNION
{ ?song wdt:P31 wd:Q856713. }
?song wdt:P1433 ?songbook.
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
?songbook rdfs:label ?name.
}
}
GROUP BY ?songbook ?name
ORDER BY DESC (?songs)
LIMIT 100
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?name"):::projected
v2("?song"):::projected
v3("?songbook"):::projected
v5("?songs")
c2(["wd:Q7366"]):::iri
c6(["bd:serviceParam"]):::iri
c8(["#91;AUTO_LANGUAGE#93;,en"]):::literal
c3(["wd:Q856713"]):::iri
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v2 --"wdt:P31"--> c3
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v2 --"wdt:P31"--> c2
end
union0r <== or ==> union0l
end
v2 --"wdt:P1433"--> v3
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c6 --"wikibase:language"--> c8
v3 --"rdfs:label"--> v4
end
bind1[/"count(?song)"/]
v2 --o bind1
bind1 --as--o v5