Slick query with multiple joins, group by and having
Just in case someone is looking for it (derived from slick docs)
(for { //joins book <- books bookAuthor <- bookAuthors if book.id === bookAuthor.bookId author <- authors if bookAuthor.authorId === author.id} yield (author, book.id)).groupBy({ //group by author case (author, bookId) => author}).map({ //count bookIds case (author, authorBookIds) => (author, authorBookIds.map(_._2).count) //having count bookIds >= 3}).filter(_._2 >= 3)// order by count desc.sortBy(_._2.desc)// limit 5.take(5)