我需要你的帮助:
我为用户、游戏和结果设置了一组关系表,我正在尝试计算每个用户的获胜百分比。
感谢大量浏览,我发现了以下方法:
SELECT Winner, (COUNT(Winner) * games.TotalPlayed) AS PercentWon
FROM Results
JOIN (
SELECT 100/COUNT(*) AS TotalPlayed
FROM games
where Player_1 = 'John' OR Player_2 = 'John'
) AS games
where Winner == 'John'
GROUP BY Winner
ORDER BY PercentWon DESC;
这对于获取 Johns % 非常有效,但我希望它扫描整个结果表并为每个人打印值。但是,我不允许使用:
SELECT Winner, (COUNT(Winner) * games.TotalPlayed) AS PercentWon
FROM Results
JOIN (
SELECT 100/COUNT(*) AS TotalPlayed
FROM games
where Player_1 = Winner OR Player_2 = Winner
) AS games
where Winner != 'Draw'
GROUP BY Winner
ORDER BY PercentWon DESC;
因为没有定义获胜者。如何在执行子查询时将获胜者的值传递给子查询?