I checked this page INNER JOIN same table for my answer. I got part of it.
I need select id and referral link of parent(main) account which has less 7 referrals. I have this query, but it works for all parent(main) account (all account has same amount of referrals)
select
id,
referralLink
from
accs
where
( 3 > (select
count(*)
from
accs as acc
join accs as mainAcc
on mainAcc.id = acc.mainID
where
acc.paymentCompleted = 1)
and referralLink is not null)