query-97fa13fa3a34245485d02f7f46e57d7f

rq turtle/ttl

Drama schools by number of students on Wikidata

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 prov: <http://www.w3.org/ns/prov#>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:Map
# Drama schools by number of students on Wikidata
SELECT ?school ?schoolLabel ?website ?coords ?students ?sourcedStudents (FLOOR(?sourcedStudents/?students*10000)/100 AS ?layer) WHERE {
  # Total number of students on Wikidata
  {
    SELECT ?school (COUNT(?student) AS ?students) WHERE {
      ?school wdt:P31/wdt:P279* wd:Q2143781 .

      ?student wdt:P31 wd:Q5 . 
      ?student wdt:P69 ?school .
    } GROUP BY ?school ?schoolLabel
  }

  # Number of students with URL reference on Wikidata
  OPTIONAL {
    SELECT ?school (COUNT(?student) AS ?sourcedStudents) WHERE {
      ?school wdt:P31/wdt:P279* wd:Q2143781 .

      ?student wdt:P31 wd:Q5 . 
      ?student p:P69 ?schoolStatement .
      ?schoolStatement ps:P69 ?school .
      ?schoolStatement prov:wasDerivedFrom ?ref .
      ?ref pr:P854 ?url .

    } GROUP BY ?school ?schoolLabel ORDER BY DESC(?students)
  }

  # Some other useful data
  OPTIONAL { ?school wdt:P856 ?website . }
  OPTIONAL { ?school wdt:P625 ?coords . }

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
} ORDER BY DESC(?students)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v9("?coords"):::projected v10("?layer") v5("?ref") v2("?school"):::projected v4("?schoolStatement") v7("?sourcedStudents"):::projected v3("?student") v4("?students"):::projected v6("?url") v8("?website"):::projected a1((" ")) a2((" ")) c15(["en"]):::literal c13(["bd:serviceParam"]):::iri c3(["wd:Q2143781"]):::iri c4(["wd:Q5"]):::iri v2 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c3 v3 --"p:direct/P31"--> c4 v3 --"p:direct/P69"--> v2 bind1[/"count(?student)"/] v3 --o bind1 bind1 --as--o v4 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P31".-> a2 a2 --"p:direct/P279"--> c3 v3 --"p:direct/P31"--> c4 v3 --"p:P69"--> v4 v4 --"p:statement/P69"--> v2 v4 --"prov:wasDerivedFrom"--> v5 v5 --"p:reference/P854"--> v6 bind3[/"count(?student)"/] v3 --o bind3 bind3 --as--o v7 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P856".-> v8 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P625".-> v9 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c13 --"wikibase:language"--> c15 end bind4[/"numeric-floor(?sourcedStudents / ?students * '10000^^xsd:integer') / '100^^xsd:integer'"/] v7 --o bind4 v4 --o bind4 bind4 --as--o v10