Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. -- update table with select and group by statement
  2. -- Ohs my poor SQL.
  3. -- contacts:beginman.cn
  4.  
  5. update group_info as g
  6. left join (
  7. select gi.group_id, count(gm.id) as nums from group_info gi
  8. inner join group_members gm on gm.group_id = gi.group_id
  9. group by gm.group_id
  10. )
  11. as m on g.group_id = m.group_id
  12. set g.member_count = m.nums;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement