Let's say I have a users
table with two column, id
and referer_id
If the user was refered by someone else, his referrer will be in referer_id
. If he signed up by himself then the referer_id
will be NULL
I want to count how many referred users a user has.
I have a query like this
SELECT `referer_id`,count(`referer_id`) FROM `users`
GROUP BY `referer_id`
As you can see the NULL count is 0 , but I have a lot of users who was not refered by anybody. How can I solve this ?