query-1a4b09d8708926b129e029b553deb493

rq turtle/ttl

Number of IMDb ids grouped by prefix and length

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?prefix ?length ?number ?largest_id ?respective_item ?respective_itemLabel WHERE {
?respective_item wdt:P345 ?largest_id .
{SELECT ?prefix ?length (COUNT(DISTINCT(?imdb)) AS ?number) (MAX(?imdb) AS ?largest_id) WHERE {
  ?item wdt:P345 ?imdb
  BIND (SUBSTR(?imdb,1,2) AS ?prefix) .
  BIND (STRLEN(?imdb) AS ?length)
} GROUP BY ?prefix ?length} SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } ORDER BY DESC(?number)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?imdb") v4("?item") v8("?largest_id"):::projected v7("?length"):::projected v8("?number"):::projected v6("?prefix"):::projected v2("?respective_item"):::projected c3(["bd:serviceParam"]):::iri c5(["en"]):::literal v2 --"wdt:P345"--> v8 v4 --"wdt:P345"--> v5 bind0[/"substring(?imdb,'1^^xsd:integer','2^^xsd:integer')"/] v5 --o bind0 bind0 --as--o v6 bind1[/"string-length(?imdb)"/] v5 --o bind1 bind1 --as--o v7 bind4[/"count(?imdb)"/] v5 --o bind4 bind4 --as--o v8 bind5[/"max(?imdb)"/] v5 --o bind5 bind5 --as--o v8 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c3 --"wikibase:language"--> c5 end