批量Update,从另一个表中取关联的字段对应的值,来更新当前的表的joinCount值

批量Update,从另一个表中取关联的字段对应的值,来更新当前的表的joinCount值

UPDATE EventGroup g SET joinCount =(SELECT b.counts FROM (SELECT eventGroupId,SUM(1) AS counts FROM EventGroupMember WHERE groupRoleId<4 AND (memberStatus=0 OR memberStatus=3)  GROUP BY eventGroupId) b WHERE b.eventGroupId=g.eventGroupId)

WHERE EXISTS(SELECT 1

FROM (SELECT eventGroupId,SUM(1) AS counts FROM EventGroupMember WHERE groupRoleId<4 AND (memberStatus=0 OR memberStatus=3) GROUP BY eventGroupId) b

WHERE b.eventGroupId=g.eventGroupId

);

猜你喜欢

转载自liuwang126.iteye.com/blog/1840178