8 ms·
But he has a valid point in HAVING not being able to reference an aggregate column by the AS name in the SELECT.
by spthorn60 8y ago
But he has a valid point in HAVING not being able to reference an aggregate column by the AS name in the SELECT.
- blattimwind 8y agoYeah, I always considered that quite strange, given the order of the query (and even though forward references are found almost everywhere in SQL, making it even more strange) 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))