Hello guys,
I'm sure it is simple. Have a SQLAlchemy query such as:
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:
the type of the variable q is <class 'sqlalchemy.engine.row.Row'>
I tried
but of course I got this error:
Thank you
Note: I do not want a SQL query solution !
I'm sure it is simple. Have a SQLAlchemy query such as:
1 2 |
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 () |
for now I'm using this code, which works well, but I'd like to use sum() function instead:
1 2 3 |
sum = 0 for q in qp: sum + = q.total |
I tried
1 |
max_total = sum (q.total) |
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 !