首页 > 数据库技术 > 详细

【SQLAlchemy】SQLAlchemy修改查询字段列名

时间:2017-09-27 16:00:33      阅读:861      评论:0      收藏:0      [点我收藏+]
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()

【SQLAlchemy】SQLAlchemy修改查询字段列名

原文:http://www.cnblogs.com/yanglang/p/7601948.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!