结果排序表(Sorting table of results)

编程入门 行业动态 更新时间:2024-10-28 12:26:54
结果排序表(Sorting table of results)

排序赢家。

你将如何获得PHP / MYSQL竞赛的胜利者。

总价值是决定赢家的因素。 但是在平局中赢得最高价值的那个。 如果仍然画比较第二个值先比较最佳结果

数据库表具有playerid,结果字段。

Playerid result 1 100 1 80 1 80 2 100 2 80 2 40 2 40 3 160 3 100 4 130 4 130 5 270

结果列表

Player1 100,80,80 Player2 100,80,40,40 Player3 160,100 Player4 130,130 Player5 270

想要结果

Player5 Player3 Player4 Player1 Player2

Sorting a winner.

How would you get the winner of a competition PHP/MYSQL.

Total value is the factor that decides the winner. But on a draw the one with the highest value wins. Compare best result first if still draw compare the second value ..

DB table has playerid, result fields.

Playerid result 1 100 1 80 1 80 2 100 2 80 2 40 2 40 3 160 3 100 4 130 4 130 5 270

List of results

Player1 100,80,80 Player2 100,80,40,40 Player3 160,100 Player4 130,130 Player5 270

WANTED RESULT

Player5 Player3 Player4 Player1 Player2

最满意答案

只需使用group by和ORDER BY SUM(result) DESC, COUNT(*) :

SELECT PlayerId, SUM(result) res FROM resulttbl GROUP BY PlayerId ORDER BY res DESC,COUNT(*)

我猜想你希望那些入场次数较少(=较少的比赛?)的球员排在第一位,所以我增加了第二个排序标准。

或者你可以做

select PlayerId from resulttbl GROUP BY PlayerId ORDER BY sum(result) DESC, COUNT(*)

如果你不想列出结果的总和。

你可以在这里找到一个工作演示: http : //rextester.com/GTHMG11363

Simply select with group by and ORDER BY SUM(result) DESC, COUNT(*):

SELECT PlayerId, SUM(result) res FROM resulttbl GROUP BY PlayerId ORDER BY res DESC,COUNT(*)

I added the second sorting criterion as I am guessing that you want those players with fewer entries (=fewer games?) listed first.

Or you can do

select PlayerId from resulttbl GROUP BY PlayerId ORDER BY sum(result) DESC, COUNT(*)

if you don't want the sum of the results listed.

You can find a working demo here: http://rextester.com/GTHMG11363

更多推荐

本文发布于:2023-07-16 06:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1124934.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Sorting   table   results

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!