Sql Oracle Rownum,获取第n行
如何从结果列表中获取第n(第2)行,如果第2行(第2列)是某个数字,则不打印任何内容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
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”进入。与查询中的相同。因此,只有子查询位于括号之间。