User:TweetsFactsAndQueries/Queries/animals most frequently depicted in artworks

From Wikidata
Jump to navigation Jump to search

Originally posted on Twitter and on Mastodon.

SELECT ?animal ?animalLabel ?count
WITH {
  SELECT DISTINCT ?animal ?statement WHERE {
    ?work wdt:P31/wdt:P279* wd:Q838948;
          p:P180 ?statement.
    ?statement ps:P180 ?depicted.
    MINUS { ?statement wikibase:rank wikibase:DeprecatedRank. }
    ?depicted wdt:P31? ?animal.
    ?animal wdt:P279+ wd:Q729.
    MINUS { ?animal wdt:P279* wd:Q15978631. }
  }
} AS %statements
WITH {
  SELECT ?animal (SUM(COALESCE(?quantity, 1)) AS ?count) WHERE {
    INCLUDE %statements.
    OPTIONAL { ?statement pq:P1114 ?quantity. }
  }
  GROUP BY ?animal
  HAVING(?count >= 10)
} AS %counts
WHERE {
  INCLUDE %counts.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?count)
Try it!