Using alias() for 'select as' in SQLAlchemy

Solution 1:

You actually want the label method.

result = dbsession.query(Shares.price, \
                            func.sum(Shares.quantity).label("Total sold")) \
                            .filter(Shares.company== 'Google') \
                            .group_by(Shares.price).all()