繁体   English   中英

Oracle Rownum,获取第 n 行

[英]Oracle Rownum, get nth row

如何从结果列表中获取第 n(2) 行,如果第 2 行(第 2 列)是某个数字,则不打印任何内容。

Select * from
(select s.id_numeric,
         s.client_id,
         s.depth,
         s.fas_sample_type,
         s.profile_number,
         Count(1) over() as cnt
  from   sample s 
  where  s.client_id = upper ('128336A') 
  and    s.id_numeric between 12325 and 12327
  and    s.fas_sample_type = sample_pkg.get_soil_sample
  and    s.status = sample_pkg.get_authorised_sample
  and    s.flg_released = constant_pkg.get_true)
Where cnt > 1

嗯,我认为这很容易,但我花了大约 10 分钟才解决。

select * 
  from (select rownum row_num, 
               /* here_goes_rest_of_subquery */ 
         fetch first 2 rows only) sub_q
  where ...
  order by sub_q.row_num desc
  fetch first 1 row only;

请注意您的子查询没有“order by”部分,您需要结果的第 n 行。 因此,您最终可能会在不同的客户端上获得不同的结果。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM