Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Oracle Rownum,获取第n行_Sql_Oracle - Fatal编程技术网

Sql Oracle Rownum,获取第n行

Sql Oracle Rownum,获取第n行,sql,oracle,Sql,Oracle,如何从结果列表中获取第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 = up

如何从结果列表中获取第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;

请注意,您的子查询没有“orderby”部分,您需要结果的第n行。因此,您可能会在不同的客户机上得到不同的结果。

使用row\u number函数,并根据什么样的排序标准查找max number-1.“n”行?where是什么clause@user2713535“其中cnt>1”进入。与查询中的相同。因此,只有子查询位于括号之间。