How to make a quick selection and get the number of those users who have already invited at least someone?
I tried, suffered, it doesn't work:
SELECT COUNT(u.id) as `count`
FROM users u
LEFT JOIN users u1 ON u1.id=u.ref
LEFT JOIN users u2 ON u2.id=u1.ref
You need to make 1 sql, and it turns out that only the id
and ref
columns are used.
Those users who haven't invited anyone shouldn't be in the count.
Is it possible to do this or will it be necessary to use cycles and make more requests?
structure is simple - you need to get those who have invited at least someone
For this structure, it should look like this:
1 - invited? Yes!
2 - invited? Yes!
3 - invited? No!
4 - invited? Yes!
5 - invited? Yes!
6 - invited? Yes!
7 - invited? No!
Only 5.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…