python - sqlalchemy group_by and sum -


i have sitestaff table want group staff same staffid , add holiday column.

>     group =  session.query(sitestaff, func.sum(sitestaff.holiday)).group_by(sitestaff.staffid).all() >      >     print group 

the output groups staff not add column.

here sql trying mimic:

update staff p, (select staffid, sum(holiday) mysum  sitestaff group staffid) s      set p.totaldaysholidayallowed = s.mysum     p.staffid = s.staffid 

it staffsite part stopped working. needed add each field in so:

session.query(sitestaff.staffid, func.sum(sitestaff.holiday)).group_by(sitestaff.staffid).all() 

Comments