我期待着总和的一列球员属于某个特定的球队的基础上。我有一张球员桌和一张团队桌。目前,我没有任何问题,只是由于某种原因,它不会对我的查询的最后一部分求和。下面是我的代码示例:
Select SUM(points)
from (select points
from player
Join team on player.full_name=team.player1
Where team.team_id = 8
and week =9
UNION
Select points
FROM player
JOIN team on player.full_name=team.player2
Where team.team_id = 8
and week =9
UNION
Select points
FROM player
JOIN team on player.full_name=team.player3
Where team.team_id = 8
and week =9
UNION
Select points
FROM player
JOIN team on player.full_name=team.player4
Where team.team_id = 8
and week =9
任何关于为什么会发生这种情况或更好的潜在方式来完成这将不胜感激!
1条答案
按热度按时间u3r8eeie1#
您的查询似乎不完整,必须使用
UNION ALL
为了得到完整的总数(f)2或更多的球员有相同的分数UNION DISTINCT
将消除这些行):但我相信你的团队表格需要修改以获得更好的效率
请注意,使用
UNION
=UNION DISTINCT
i、 e.如果省略,则假定为“不同”。这可能更有效: