postgresql - 检查我在表中的点(字段)总和是否大于表中所有其他人的点总和。很少有活动
问题描述
我创建了一个表格,代表几支球队的体育比赛。在每场比赛中,他们都有另一个表格,显示每个球员为他的球队得分多少。我试图通过编写脚本来获得每支球队的最佳球员。每支球队的最佳球员是在他的球队所有比赛中得分最多的球员。
我写了这个脚本,它没有返回任何东西:
select nickname,pname as bestplayer
from player , points,team
where player.pid = points.pid and player.tid = team.tid
group by nickname,pname
having sum(pscore) > all(select sum(pscore)
from points,player,team
where player.pid = points.pid and player.tid = team.tid
);
出于某种原因,下面的脚本确实有效。谁能解释为什么?
select nickname,pname as bestplayer
from player , points,team
where player.pid = points.pid and player.tid = team.tid
group by nickname,pname
having sum(pscore) >= all(select count(pscore)
from points,player,team
where player.pid = points.pid and player.tid = team.tid
);
*我已将内部查询中的总和替换为计数。
解决方案
推荐阅读
- python - 字典按值写入文件
- aframe - 在场景加载时强制纹理上传到 GPU 的最佳方法?
- excel - 如何按另一个列表对列表进行排序?
- android - 处理权限:将大型应用程序的一项活动变成即时应用程序
- javascript - 当鼠标悬停在 iframe 上时,将元素向上移动 Y 轴
- javascript - 尝试渲染项目地图时出错
- python - 是否可以等到 Windows 任务管理器中的任务停止?
- excel - 在 VBA 类模块中,可以将私有实例变量显式限定为来自同一类的公共 Enum 吗?
- elasticsearch - 如何使用 Kibana 和 ElasticSearch 过滤掉空白消息?
- linux - Visual Studio 2017 Linux 调试外部可执行文件的子进程