Hello guys,
I'm sure it is simple. Have a SQLAlchemy query such as:
for now I'm using this code, which works well, but I'd like to use sum() function instead:
I tried
Thank you
Note: I do not want a SQL query solution !
I'm sure it is simple. Have a SQLAlchemy query such as:
qp = db.session.query(UInventory, func.sum(UInventory.quantity).label('total')).filter( UInventory.location_id == s.loc_id, UInventory.userid == current_user.userid).group_by(UInventory.part_id). subq.all()Later in my code, I want to sum up the result of the 'total' from the query.
for now I'm using this code, which works well, but I'd like to use sum() function instead:
sum = 0 for q in qp: sum += q.totalthe type of the variable q is <class 'sqlalchemy.engine.row.Row'>
I tried
max_total = sum(q.total)but of course I got this error:
Error:print(sum(qp.total))
AttributeError: 'list' object has no attribute 'total'
How can I achieve something that simple ? Thank you
Note: I do not want a SQL query solution !