Get the top row after order by in Oracle Subquery

前端 未结 4 1577
一整个雨季
一整个雨季 2021-02-15 17:19

I have a table student(id, name, department, age, score). I want to find the youngest student who has the highest(among the youngest students) score of each department. In SQL S

4条回答
  •  借酒劲吻你
    2021-02-15 18:00

    try this one

    select * from
      (SELECT id, name, department, age, score,
      ROW_NUMBER() OVER (partition by department order by age desc, score asc) srlno 
      FROM student) 
    where srlno = 1;
    

提交回复
热议问题