I have two tables in my database, one table holds the registered users and other table for referrals.
Below is the referrals table
What I want to do is to make an SQL query that returns the referral name "rname" and all users referred by this referral (total users and premium users)
In the users table, I have a column named "package" of type INT, if the value of this column is bigger than 0 then the user is premium, otherwise, the user isn't premium.
The "ruser_referred" column in the image above represents the id of the user being referred.
So the result should look like this (supposing only user with id 21 is premium)
Referral Total Users Referred Premium Users Referred
rafik 3 1
samia 1 0
mourad 1 0