我有两个column_property
列,我希望在grandtotal
列中汇总。我希望能够对grandtotal
列进行排序和过滤。
如何汇总subtotal
和shipping
列'值?
代码:
subtotal = orm.column_property(
select([case(
[(func.sum(OrderProductModel.subtotal).is_(None), 0)],
else_=func.sum(OrderProductModel.subtotal))
]).where(OrderProductModel.order_id == id))
shipping = orm.column_property(case(
[(is_expedited.is_(True), shipping_rate)], else_=Decimal(0.00)))
grandtotal = orm.column_property(func.sum(subtotal + shipping))
错误:
TypeError: unsupported operand type(s) for +: 'ColumnProperty' and 'ColumnProperty'
答案 0 :(得分:1)
您需要汇总此列属性的expressions
grandtotal = orm.column_property(func.sum(subtotal.expression + shipping.expression))