Find second highest record from oracle db [duplicate]

两盒软妹~` 提交于 2019-12-02 08:47:45

You could use:

SELECT *
FROM (SELECT *, ROW_NUMBER() OVER(PARTITION BY id ORDER BY mia DESC) AS rn
      FROM table) sub
WHERE rn = 2;

you may not define a column named as date, instead i use date_. For former versions you may refer to @lad2025 's answer, if you're on oracle12c, you may query with the following :

select min(date_) min_date 
  from
(
 select date_
   from mytable
  where id = &i_id
  group by id, date_
  order by date_
  fetch first 2 rows only
 );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!