0

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?

4
  • what you have tried so far? Commented Oct 9, 2020 at 9:20
  • Nothing in particular unfortunately, I can not find a logic of how to behave, I am stuck. Commented Oct 9, 2020 at 9:36
  • 1
    Thank you very much, I have tried and apparently it work! Commented Oct 9, 2020 at 9:48
  • Have also a look at stackoverflow.com/questions/24887708/… Commented Oct 9, 2020 at 13:52

1 Answer 1

1

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

Point::selectRaw("SUM(quantity) as total_quantity,user_id")->groupBy('user_id')->get()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.