query-5510d6e322cfd253d91122c5b03b793b
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
- https://query.wikidata.org/sparql
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)