当前位置:Gxlcms > 数据库问题 > oracle 分组查询

oracle 分组查询

时间:2021-07-01 10:21:17 帮助过:1人阅读

球员信息表 T:

球员id      球员名称      所在球队    

12344       麦迪             火箭

34323       科比             活人

球员赛季得分表A,字段如下:

    id         球员id         赛季         场均得分

   01         34323          2013           34

   02         12344          2013           12

   03         43221          2013           23

   04         12344          2014           20

   05         43221          2014           26

   06        34323           2014           38

   .......

获取球员的往期赛季的最高得分 :  球员名称     所在球队   赛季     最高得分     

select t.球员名称,t.所在球队,b.赛季,b.场均得分  from (

  select * from (

       select  a.* ,row_number() over(partition by a.球员id order by a.场均得分 desc) rn  from a

   )  c  where c.rn =1

) b ,t  where t.球员id = b.球员id

 

oracle 分组查询

标签:

人气教程排行