zoukankan      html  css  js  c++  java
  • 【SQLAlchemy】SQLAlchemy修改查询字段列名

    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()
  • 相关阅读:
    Java基础知识整理
    HashMap源码解读(JDK1.7)
    书籍列表
    mysql4
    mysql3
    mysql2
    mysql1
    数据结构4
    数据结构3
    数据结构2
  • 原文地址:https://www.cnblogs.com/yanglang/p/7601948.html
Copyright © 2011-2022 走看看