我有一张GAMES表,其中包含以下信息:
Id_Game Id_Player1 Id_Player2 Week
--------------------------------------
1211 Peter John 2
1215 John Louis 13
1216 Louis Peter 17
我想获得每个玩家玩过的最后一周的列表,以及应该是这样的游戏数量:
Id_Player Week numberGames
-----------------------------
Peter 17 2
John 13 2
Louis 17 2
但我得到了这个(关于彼得周的通知):
Id_Player Week numberGames
-----------------------------
Peter 2 2
John 13 2
Louis 17 2
我的工作是:
SELECT Id_Player,
MAX(Week) AS Week,
COUNT(*) as numberGames
FROM ((SELECT Id_Player1 as Id_Player, Week
FROM Games)
UNION ALL
(SELECT Id_Player2 as Id_Player, Week
FROM Games)) AS g2
GROUP BY Id_Player;
有人能帮助我找到错误吗?
答案 0 :(得分:7)
Week
列的数据类型是什么?如果Week
的数据类型是varchar,则会出现此行为。