oracle 中表数据如下 主键id 是uuid 不是数字 需要得到结果使用如下sql 查询结果 没有 id,我就要得到 最小成绩的 id

解决方案 »

  1.   

    select scoreid,kc,cj 
      from score b
       left join (select max(cj) as cj,kc from score a group by kc) c on b.cj=c.cj and b.kc=c.kc;如果最小成绩有多个。会有多条数据。
      

  2.   

    Quote: 引用 1 楼 weixin_42581861 的回复:

    select scoreid,kc,cj 
      from score b
       left join (select max(cj) as cj,kc from score a group by kc) c on b.cj=c.cj and b.kc=c.kc;如果最小成绩有多个。会有多条数据。用group by的作为主表再去关联一次
      

  3.   

    select distinct 
           first_value(id) over(partition by kc order by cj desc) id,
           kc,
           min(cj) over(partition by kc) cj
      from student;
      

  4.   


    select id, kc, cj
      from (select id,
                   kc,
                   cj,
                   row_number() over(partition by kc order by cj) as rn
              from table)
     where rn = 1;