MySQL分组查询一个例子

需求:
查询当前ID邀请的人,再次邀请人的数量。

语句:
首先通过邀请人ID分组,再进行COUNT

SELECT invited_id as uid,COUNT(1) as total FROM `sh_user` WHERE `invited_id` in (SELECT id FROM sh_user WHERE invited_id=615 and is_proxy=1 )   GROUP BY `invited_id` HAVING COUNT(*) > 0

你可能感兴趣的:(MySQL分组查询一个例子)