0

我希望能够SELECT opponents id from a db table WHERE id=$currplayer

我的数据库表是这样的: fk_player fk_opponent

如果我这样做:

SELECT fk_opponent
     , COUNT(fk_opponent) AS oplay 
FROM nf_newversus 
     GROUP BY fk_opponent

它做对了,但我希望能够对此进行排序,所以它只是那些 fk_player = $currplayer... 我试图插入 aWHERE fk_player = $currplayer但这是不对的...

任何帮助表示赞赏。

4

2 回答 2

1

根据您的描述,这应该是正确的:

SELECT fk_opponent, COUNT(*) AS oplay
FROM nf_newversus 
WHERE fk_player='$currplayer'
GROUP BY fk_opponent

如果您的表允许多个player1 vs player2(即没有UNIQUE(fk_player, fk_opponent)索引),那应该可以正常工作,但假设您以两种方式存储匹配项

于 2012-10-03T10:59:16.820 回答
1
SELECT fk_opponent
     , COUNT(fk_opponent) AS oplay
FROM nf_newversus 
WHERE fk_player = '$currplayer'
GROUP BY fk_opponent
于 2012-10-03T11:54:48.500 回答