1: mysql> select inviteuserid from user where userid= 1 and inviteuserid in (select userid from user group by userid having count(userid)>=10);
select a.userid, count(a.inviteuserid) from user a where exists ( select b.userid, count(b.inviteuserid) from user b where b.userid = a.inviteuserid group by b.userid having count(b.inviteuserid) >=10 );
错了,应该是mysql> select count(inviteuserid) from user where userid= 1 and inviteuserid in (select userid from user group by userid having count(userid)>=10);
mysql> select * from user where userid= 1 and inviteuserid in (select userid from user group by userid having count(userid) between 10 and 35);
to VIPPER23:userid 每行都不一样, 那么group by有何意义呢? select userid from user group by userid having count(userid)>=10
select a.userid, count(a.inviteuserid) from user a where exists ( select b.userid, count(b.inviteuserid) from user b where b.userid = a.inviteuserid group by b.userid having count(b.inviteuserid) >=10 ) and a.userid=1 group by a.userid;--
没仔细看,是邀请此用户的id,我看成此用户邀请的ID了 LZ给点测试的数据吧。
算了, 数据太大,放不上来. 不过还是谢谢了, 已经解决了, 贴一下, 也给分select count(1) as counter,inviteuserid from USER where inviteuserid IN(SELECT USERID FROM USER WHERE inviteuserid="+userId+") group by inviteuserid having counter>10select count(1) as counter,inviteuserid from USER where inviteuserid IN(SELECT USERID FROM USER WHERE inviteuserid in(select userid from USER where status="+level+" and emailstatus=1)) group by inviteuserid having counter>10
mysql> select inviteuserid from user where userid= 1 and inviteuserid in (select userid from user group by userid having count(userid)>=10);
from user a
where exists ( select b.userid, count(b.inviteuserid)
from user b
where b.userid = a.inviteuserid
group by b.userid
having count(b.inviteuserid) >=10 );
select userid from user group by userid having count(userid)>=10
from user a
where exists ( select b.userid, count(b.inviteuserid)
from user b
where b.userid = a.inviteuserid
group by b.userid
having count(b.inviteuserid) >=10 )
and a.userid=1
group by a.userid;--
没仔细看,是邀请此用户的id,我看成此用户邀请的ID了
LZ给点测试的数据吧。