簡體   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