Taking the answer by Sean Larkin as a starting point I ended up with something like this:
actors = repository(:default).adapter.select(
"SELECT actors.name, count(actor_movies.actor_name) AS count " +
"FROM actors " +
"JOIN actor_movies WHERE actors.name = actor_movies.actor_name " +
"GROUP BY actors.name " +
"ORDER BY count(actor_movies.actor_name) desc " +
"LIMIT 5;"
)
=> [
#<struct name="Samuel L. Jackson", count=66>,
#<struct name="Michael Caine", count=64>,
#<struct name="Robert De Niro", count=59>,
#<struct name="Harvey Keitel", count=58>,
#<struct name="Gene Hackman", count=57>
]