User:TweetsFactsAndQueries/Queries/actors who played the same real politician the most times

Originally posted on Twitter and on Mastodon. For a very loose interpretation of “politician”: anybody with a position held (P39). I think the top results can all be fairly called politicians, at least.

SELECT ?actor ?actorLabel ?characterLabel ?count WITH {
  SELECT ?actor ?character (COUNT(DISTINCT ?film) AS ?count) WHERE {
    ?film wdt:P31/wdt:P279* wd:Q11424;
          p:P161 [
            ps:P161 ?actor;
            pq:P453 ?character
          ].
    FILTER(?actor != ?character)
    ?character wdt:P31 wd:Q5;
               wdt:P39 ?position.
  }
  GROUP BY ?actor ?character
  HAVING(?count > 1)
  ORDER BY DESC(?count)
  LIMIT 100
} AS %results WHERE {
  INCLUDE %results.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?count)
LIMIT 100
Try it!