sql-server - 统计玩家的sql查询
问题描述
在特定国家/地区的领先者的 500 场比赛中得分的球员计数。例如,如果印度 A 得分 1500 分,那么有多少球员得分超过 1000 分。
我已经运行了这段代码,但这并没有给我想要的结果。
select COUNT( [Player ] )as no_of_players,country from [dbo].[Sheet1$]
where runs >=
All (select max(runs)-500 from [dbo].[Sheet1$] group by country )
group by country
解决方案
您可以为此使用窗口函数
SELECT
COUNT(*) AS no_of_players,
country
FROM (
SELECT *,
MAX(runs) OVER (PARTITION BY country) AS MaxRuns
FROM [dbo].[Sheet1$] s1
) s1
WHERE runs >= MaxRuns - 500;
请注意,与或
COUNT(nonNullValue)
相同COUNT(*)
COUNT(1)
推荐阅读
- android - 如何更改背景可绘制 xml 中项目的颜色?
- c# - 如何在 asp.net mvc 中按浏览器类型显示视图?
- python - Gimp python-fu:选择两层
- angular - WebStorm 中的 Auth0 'Unresolved Type WebAuth'
- python - 在 Python 中计算大分数?
- git - 使用 git 推送新版本而不丢失旧版本
- android - 如何启用在 TabBarView 父级中禁用的 Listview 滚动
- sql - 从 VBA 执行存储过程时出现错误“过程或函数需要未传递的参数 @empid”
- design-patterns - 如何消除代码中的 switch-case?
- angularjs - 使用 ASP.NET MVC 在 AngularJS 应用程序中缩小 javascript 文件时无法实例化模块