T
T
Troodi Larson2020-02-23 16:31:21
Laravel
Troodi Larson, 2020-02-23 16:31:21

I can't make a complex query on Lara?

Good afternoon! Please help me to make such a query with the help of DB (I tried to join everything correctly, but it doesn’t work):
2 tables:
inviteds - referral system table (user_id - invited, referer - inviting)
users - obviously
The task itself is this: you need to count the number of referral invitations by descending (for example, testuser invited 120 referrals, and testuser2 invited 50 referrals), but inviteds.user_id should also have user.active = 1.
Active = 1 means that the user confirmed the mail, that is, both the invitee and the inviter should have users.active= one.
Is it possible to compose this with a request, I did not succeed, I tried - honestly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antonio Solo, 2020-02-23
@troodi

in extreme cases, use DB::statement and DB::raw - you write regular SQL there,
but what you need (as I understand it) - in a subquery you count the number of children by parents, then you join with the parent.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question