python - Flask_SQLAlchemy select, where, scalar, connection_execute
问题描述
我想知道如何使用没有 Flask 扩展但具有在模板中吸引价值(结果)的选项的 SQLalchemy 来编写如下所示的请求:
class Finance(db.Model):
__tablename__=='MAIN'
id = db.Column(db.Integer, primary_key=True)
month = db.Column(db.Integer)
cost_with_vat = db.Column(db.Integer)
profit = db.Column(db.Integer)
我想编写相同的请求,就像我可以通过 SQLAlchemy(我在下面写的)一样,没有 Flask 扩展。
profit = select([func.sum(order.columns.profit)])
profit = profit.where(or_(
order.columns.cost_with_vat>0,
order.columns.cost_with_vat=='?'))
profit_month = profit.where(order.columns.month==11)
result = connection.execute(profit_month).scalar()
需要在模板中显示结果
@app.route('/')
def index():
return '''<h1>{{result}}</h1>'''
解决方案
推荐阅读
- android - 有没有办法访问在 ARCore 中已知 3D 坐标的点的 RGB 值?
- json - 导入/加载几个大 JSON 文件的方法
- python - 将字符串转换为列表 Python
- openstack - openstack 错误 CRITICAL keystone [-] 未处理错误:KeyError: 'connection'
- windows - 迭代目录中的文件 - 使用包含 % 的参数发出命令
- php - 在 url 中发布 Json 数组
- python-hypothesis - 如何在假设中设置数据帧的最小和最大长度?
- python - 在 PyQt5 中使用 cv2.imshow 和 drawpixmap 的颜色图是不同的
- xcode - Xcode 不会自动完成任何 Alamofire 方法
- python - 随着学习率变小,验证集的准确度高于 LSTM RNN 的训练集