求id = 3 下面的 1级关系人数,2级关系人数 关联字段refferee
解决方案
40
改一下:
SELECT t.username , COUNT(distinct t1.id) onelevel, COUNT(t2.id) twolevel FROM tb t LEFT JOIN tb t1 ON t.id = t1.refferee LEFT JOIN tb t2 ON t1.id = t2.refferee GROUP BY t.username
40
改一下:
SELECT t.username , COUNT(distinct t1.id) onelevel, COUNT(t2.id) twolevel FROM tb t LEFT JOIN tb t1 ON t.id = t1.refferee LEFT JOIN tb t2 ON t1.id = t2.refferee GROUP BY t.username