SQLAlchemy问题记录

company    price    quantity
Microsoft  100      10
Google     99       5
Google     99       20
Google     101      15

 


要实现脚本
select price, sum(quantity) as num from shares where company='Google' group by price;

SQLAlchemy写法

你实际上需要label()方法。

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2021-10-06
  • 2021-09-18
  • 2021-10-12
  • 2022-01-19
  • 2021-06-06
猜你喜欢
  • 2021-07-15
  • 2021-08-29
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案