query-8d31e07c700b373abf507713f39a8802
Propertiesinstance of (P31)PM20 subject code (P8484)main subject (P921)PM20 folder ID (P4293)number of works accessible online (P5592)
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 ?top ?topCode ?topLabel ?folderCount ?docCount
where {
{
select ?topCode (count(*) as ?folderCount) (sum(?folderDocCount) as ?docCount)
where {
?item wdt:P31 wd:Q91257459 .
?item p:P921 ?statement .
?statement pq:P8484 ?subjectCode .
bind(substr(?subjectCode, 1, 1) as ?topCode)
optional {
?item p:P4293 ?statement2 .
?statement2 pq:P5592 ?folderDocCount .
filter(isLiteral(?folderDocCount))
}
}
group by ?topCode
}
?top wdt:P31 wd:Q92707903 ;
wdt:P8484 ?topCode .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], en". }
}
order by desc(?folderCount)
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v8("?docCount"):::projected
v8("?folderCount"):::projected
v2("?folderDocCount")
v3("?item")
v4("?statement")
v7("?statement2")
v5("?subjectCode")
v9("?top"):::projected
v6("?topCode"):::projected
c7(["wd:Q92707903"]):::iri
c10(["bd:serviceParam"]):::iri
c12(["#91;AUTO_LANGUAGE#93;, en"]):::literal
c2(["wd:Q91257459"]):::iri
v3 --"p:direct/P31"--> c2
v3 --"p:P921"--> v4
v4 --"p:qualifier/P8484"--> v5
bind0[/"substring(?subjectCode,'1^^xsd:integer','1^^xsd:integer')"/]
v5 --o bind0
bind0 --as--o v6
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v3 -."p:P4293".-> v7
v7 --"p:qualifier/P5592"--> v2
end
bind3[/"count(*)"/]
bind3 --as--o v8
bind4[/"sum(?folderDocCount)"/]
v2 --o bind4
bind4 --as--o v8
v9 --"p:direct/P31"--> c7
v9 --"p:direct/P8484"--> v6
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c10 --"wikibase:language"--> c12
end