I have a SiteStaff table that I want to group all the staff together with the same staffId and add up the holiday column.
> group = session.query(SiteStaff, func.sum(SiteStaff.Holiday)).group_by(SiteStaff.StaffID).all()
>
> print group
The output groups the staff together but does not add the column.
Here is the sql that i am trying to mimic:
UPDATE Staff p, (SELECT StaffID, SUM(Holiday) as mysum
FROM SiteStaff GROUP BY StaffID) as s
SET p.TotalDaysHolidayAllowed = s.mysum
WHERE p.StaffID = s.StaffID
It was the StaffSite part that stopped it from working. I needed to add each field in like so:
session.query(SiteStaff.StaffID, func.sum(SiteStaff.Holiday)).group_by(SiteStaff.StaffID).all()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With