1

我目前正在处理一个 SQLite 查询,该查询必须向我返回所有能够履行游戏中每个角色的玩家。我目前有这个代码:

SELECT pr.name 
    FROM (SELECT DISTINCT p.name name, c.role role
            FROM players p, playerchampions pc, champions c 
                WHERE (p.name = pc.playername) & (pc.championname = c.name)) pr
                    WHERE COUNT(pr.name) = COUNT(DISTINCT pr.role)

这个想法是我只是检查玩家是否可以完成与游戏中不同角色相同数量的角色,但我得到了滥用聚合函数 COUNT() 错误。我该如何处理?

4

1 回答 1

0

这个查询可以这样写:

SELECT players.name
FROM players
JOIN playerchampions ON players.name = playerchampions.playername
GROUP BY players.name
HAVING COUNT(playerchampions.championname) = (SELECT COUNT(DISTINCT role)
                                              FROM champions)
于 2013-04-11T12:43:51.987 回答