Using alias() for 'select as' in SQLAlchemy

前端 未结 1 705
别那么骄傲
别那么骄傲 2020-12-03 13:23

Let\'s say I have a table \'shares\' with the following columns:

company    price    quantity
Microsoft  100      10
Google     99       5
Google     99              


        
相关标签:
1条回答
  • 2020-12-03 13:47

    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()
    
    0 讨论(0)
提交回复
热议问题