다음 표를 다시 가져 오는 쿼리가 있습니다. 마지막 열은 Total_points
을 Games_played
으로 나누어 마지막 열에 Points_Per_Game
숫자를 얻습니다.이 쿼리로 인해 나눗셈이 잘못되는 이유는 무엇입니까?
이 테이블 여기
+----------+--------------+--------+-----------------+
| PlayerID | Games_Played | Points | Points_Per_Game |
+----------+--------------+--------+-----------------+
| 16 | 2 | 3 | 0.6000 |
| 20 | 2 | 3 | 0.6000 |
| 10 | 2 | 3 | 0.3750 |
| 18 | 2 | 3 | 0.3750 |
| 5 | 2 | 3 | 0.3750 |
| 9 | 2 | 3 | 0.3750 |
+----------+--------------+--------+-----------------+
6 rows in set (0.00 sec)
이
SELECT Players.PlayerID, COUNT(Games.Points) AS Games_Played,
SUM(Games.Points) AS Points, SUM(Points/Games_Played) AS Points_Per_Game
FROM Teams, Players, Games
WHERE
Teams.PlayerID=Players.PlayerID
AND
Games.Game=Teams.Game
AND
Games.Team=Teams.Team
AND
Games.GameDate=Teams.GameDate
AND
(
CONCAT(Games.Game, '_', Games.GameDate)=
ANY(SELECT CONCAT(Teams.Game, '_', Teams.GameDate)
FROM Teams WHERE PlayerID='4')
AND NOT
CONCAT(Games.Game, '_', Games.Team, '_', Games.GameDate)=
ANY(SELECT CONCAT(Teams.Game, '_', Teams.Team, '_', Teams.GameDate)
FROM Teams WHERE PlayerID='4')
)
GROUP BY Teams.PlayerID
ORDER By Points_per_Game DESC, Points DESC, Games_Played;
내가 의한 그룹화하고 참조하는 열을 합산하고 있다는 사실과 함께 할 수있는 뭔가가있는 쿼리입니다?
나는 당신의 Games_Played가 올바른지 또는 가장 오해의 소지가 아니었다 ....
SELECT Players.PlayerID, COUNT(Games.Game) AS Games_Played,
SUM(Games.Points) AS Points, SUM(Games.Points)/COUNT(Games.Game) AS Points_Per_Game
FROM Teams, Players, Games
이 시도 1.5
http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple- sql-query – Strawberry
게임이 제대로 실행되지 않는다 – AntDC
@Strawberry 나는 분명히 제안을 받아 들일 것이다. – denski