user12997763
user12997763

Reputation:

List of users with the highest sum of points

I would like to create a ranking ordered by the user who has the most "points" scored.

My "points" table has these fields: user_id, type and quantity.

enter image description here

In this example, user 1 has a total of 4 points, while user 2 has a total of 8.

My dilemma after several unsuccessful tests, is to create a cycle that shows users with the highest sum of "quantity".

How can I do?

Upvotes: 0

Views: 114

Answers (1)

Kamlesh Paul
Kamlesh Paul

Reputation: 12401

you need to use selectRaw(sum(columan) as total) then group

Point::selectRaw("SUM(quantity) as total_quantity,user_id")->groupBy('user_id')->get()

Upvotes: 1

Related Questions