Created
June 2, 2015 05:34
-
-
Save limboinf/55187865b13e5289f69a to your computer and use it in GitHub Desktop.
mysql update whit select and group by
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- update table with select and group by statement | |
-- Ohs my poor SQL. | |
-- contacts:beginman.cn | |
update group_info as g | |
left join ( | |
select gi.group_id, count(gm.id) as nums from group_info gi | |
inner join group_members gm on gm.group_id = gi.group_id | |
group by gm.group_id | |
) | |
as m on g.group_id = m.group_id | |
set g.member_count = m.nums; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment