List of users with the highest sum of points

久未见 提交于 2021-01-29 20:59:30

问题


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.

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?


回答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()


来源:https://stackoverflow.com/questions/64276912/list-of-users-with-the-highest-sum-of-points

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!