sql - 只选择一个列,例如玩家,首先选择一个最大值,然后选择一个最小值
问题描述
所以我有两张表“AllBowlRecords”和一张“AggregateBowlRecords”
AllBowlRecords:-
plr_fullnm|Wkts|Runs
---------------------
Bumrah | 4 | 23
Bumrah | 2 | 7
Bumrah | 1 | 51
Bumrah | 4 | 39
Jason | 3 | 48
Jason | 3 | 29
Jason | 3 | 70
所以我想要的只是根据 Wkts 为 MAX 的 AllBowlRecords 更新 AggregateBowlRecords,但如果多次出现 MAX Wkts 值,则应选择对应的最小运行次数。AggregateBowlRecords 应该是这样的:
Bumrah | 4 | 23
Jason | 3 | 29
有哪些可能的解决方案?
解决方案
您可以使用以下查询返回所需的结果row_number()
:
select plr_fullnm, Wkts, Runs
from (select abr.*,
row_number() over (partition by plr_fullnm order by wkts desc, runs) as seqnum
from AllBowlRecords abr
) abr
where seqnum = 1;
推荐阅读
- node.js - 节点 + 反应 + heroku,节点路由 404(未找到)
- r - 处理 R 的 ff 库中用引号括起来的实数
- java - 使用 Criteria API 的复杂请求
- javascript - D3.js 中不同条数的条形图
- ios - 如何为collectionView Cell的cellForItemAt中的子视图着色?
- intellij-idea - Intellij:如何转换所有文件的缩进
- linux - 从巨大的 txt.gz 文件中选择/复制包含字符串的行的最快方法
- r - 将列乘以 R 中的子字符串
- java - Spring boot 和 Flyway:集成测试前清除数据库数据
- xml - 将现有 XML 文件中的节点附加到新的 XML 文档中