WHERE filters input rows
HAVING filters produced rows
Questions?
HAVING filters produced rows
Questions?
ORM-wise it's not a huge issue, I tend to move them outside the query definition to avoid the duplication. E.g.
comment_count = func.count(Comment.id).label('comment_count')
query = (session.query(User, comment_count)
.join(User.comments)
.group_by(User)
.having(comment_count > 10))