query-5510d6e322cfd253d91122c5b03b793b

rq turtle/ttl

HAVING statements on Wikidata. (P1104)number of pages , which skews the results a bit. To remove outliers like that, we could try to select only publishers that published at least two books with (Q3775610)Grande dizionario della lingua italiana statement, (P1104)number of pages ) only published a single book with a (Q4002388)UTET A small addendum to that last query – if you look at the results, you might notice that the top result has an outrageously large average, over ten times that of the second place. A bit of investigation reveals that this is because that publisher ( does: FILTER clause and takes an expression just like GROUP BY clause, which can be placed right after a HAVING clause, but in this case we want to restrict based on the group (the number of books), not any individual result. This is done with a FILTERHow do we do that? Normally, we restrict results with a

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?publisher ?publisherLabel (AVG(?pages) AS ?avgPages)
WHERE
{
  ?book wdt:P123 ?publisher;
        wdt:P1104 ?pages.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?publisher ?publisherLabel
HAVING(COUNT(?book) > 1)
ORDER BY DESC(?avgPages)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?_anon_42b5416610844a34809f33a099ae9de1105252") v6("?avgPages") v2("?book") v4("?pages"):::projected v3("?publisher"):::projected a1((" ")) c5(["bd:serviceParam"]):::iri c7(["en"]):::literal f0[[" > '1^^xsd:integer'"]] f0 --> a1 v2 --"wdt:P123"--> v3 v2 --"wdt:P1104"--> v4 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c5 --"wikibase:language"--> c7 end bind3[/"count(?book)"/] v2 --o bind3 bind3 --as--o v5 bind4[/"average(?pages)"/] v4 --o bind4 bind4 --as--o v6