SELECT
PlayerName, ROUND(SUM(A)/SUM(TO),2) AS ATORatio
FROM
Players_t
INNER JOIN
GameStats_t ON Players_t.JerseyNumber=GameStats_t.JerseyNumber
WHERE
ATORatio < (SELECT SUM(A)/SUM(TO) FROM GameStats_t)
GROUP BY
PlayerName;
我需要归还ATORatio
低于平均值的所有玩家。为什么这段代码不起作用?
答案 0 :(得分:1)
下面应该有所帮助:
SELECT
PlayerName, ROUND(SUM(A)/SUM(TO),2) AS ATORatio
FROM
Players_t
INNER JOIN
GameStats_t ON Players_t.JerseyNumber=GameStats_t.JerseyNumber
GROUP BY
PlayerName;
HAVING ----> You can also use WHERE here
ROUND(SUM(A)/SUM(TO),2) < (SELECT SUM(A)/SUM(TO) FROM GameStats_t)
问题是,在执行where或having子句时,最初不会知道ATORatio。因此,您需要在where或having子句中使用字段ATORatio的值本身。