By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE
CREATE TABLE
INSERT 0 7
INSERT 0 5
| id | premium | |
|---|---|---|
| 1 | some@email.com | t |
| 2 | another@email.com | f |
| 3 | third@email.com | t |
| 4 | fourth@email.com | t |
| 5 | fifth@email.com | t |
| 6 | sixth@email.com | f |
| 7 | seventh@email.com | t |
SELECT 7
| id | referrer |
|---|---|
| 2 | 1 |
| 3 | 1 |
| 4 | 1 |
| 5 | 2 |
| 6 | 2 |
SELECT 5
| id | premium | referred | |
|---|---|---|---|
| 1 | some@email.com | t | 2 |
| 2 | another@email.com | f | 1 |
| 3 | third@email.com | t | 0 |
| 4 | fourth@email.com | t | 0 |
| 5 | fifth@email.com | t | 0 |
| 6 | sixth@email.com | f | 0 |
| 7 | seventh@email.com | t | 0 |
SELECT 7