Answer the question
In order to leave comments, you need to log in
SQL. How to find out which ref_id how many times are repeated?
Good afternoon, there is a Users table
. There are fields in it: id and ref_id
id - a unique number of each user
ref_id - referrer id (may be NULL if no one invited the user)
The task is this:
You need to make a query that will display the top users who invited the most people (display id and number of referrals)
referrer - a person who invites users to the system
referral - a person who was invited
Thank you in advance for your help!
Answer the question
In order to leave comments, you need to log in
Like this?
SELECT id as refer, count(ref_id) as refers_count
FROM users
WHERE
ref_id is not null
GROUP BY ref_id
ORDER BY 2 DESC LIMIT 5;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question