jeudi 24 septembre 2020

Get the details but ignore user if exist another higher level

I have a table looks like

id  user_id  level

1     1        1
2     1        2
3     2        1
4     3        1

Here user id 1 exist in level 1 and level 2 Now when we count group by level then in counting we want ignore user_id 1 from level 1 cause it exist another group. we want to consider only one group existing and higher group.

I have done only group count but cant understand how ignore counting.

My current query is

UserCertificate::with('user')->where('level','1')->distinct('level')->orderBy('id','ASC')->get();

My Query return counting

id  user_id  level

1     1        1
3     2        1
4     3        1

But I want looks like

id  user_id  level

3     2        1
4     3        1

User Id 1 will be ignored cause it exist in level 2



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire