0

我有一个包含 id、player1 和 player2 列的表。玩家的 ID 可以在两列中的任何一列中。我需要在 player1 列和 player2 列中找到所有唯一 ID。然后我还需要找到每个玩家出现在每列中的次数。最后我想按列player1/列player2的比例排序。

例如,我在表中有以下值。

1 103 101

2 103 111

3 232 103

4 223 111

我的查询将返回..

玩家 223:1/0

玩家 232:1/0

玩家 103:2/1

玩家 101:0/1

玩家 111:0/2

我知道对于唯一 ID,我可以做这样的事情

select 
(SELECT group_concat(DISTINCT player1) FROM table) as player1,
(SELECT group_concat(DISTINCT player2) FROM table) as player2

我知道为了订单我可以做这样的事情

ORDER BY player1 / player2 DESC

我真的很难弄清楚一旦我获得唯一 ID 后该怎么做,然后尝试输出和排序比率

4

1 回答 1

0

尝试这个

select player1,player2, CONCAT('Player',IF( (select count(DT.player1) from table as DT where MT.player1 = DT.player1) > 0, player1,player2),':', (select count(DT.player1) from table as DT where MT.player1 = DT.player1), ' / ', (select count(DT.player2) from table as DT where MT.player2 = DT.player2) )  
from table MT
where player1 != player2
group by palyer1,player2
order by (player1/IF(player2 is not null and player2 != 0,player2,1) desc

希望对你有帮助

于 2013-10-07T10:45:19.503 回答