这是查询的输出"选择*来自ProductAmount desc&#34的FindNthHighestNumber订单;
我想要上面图像的带边绿色部分的个别值。我怎样才能做到这一点?比如row =' 2'
答案 0 :(得分:0)
Select *,Row_number(PARTITION BY ID ORDER BY (SELECT NULL)) from Table
答案 1 :(得分:0)
我相信这就是你想要的:
select f.*, row_number() over (order by f.ProductAmount desc)
from FindNthHighestNumber f
order by f.ProductAmount desc;
如果您只想要数字,请从f.*
中删除select
。如果要选择特定值,则一种方法是使用子查询:
select f.*
from (select f.*, row_number() over (order by f.ProductAmount desc) as seqnum
from FindNthHighestNumber f
) f
where seqnum = 2;
或者,如果您只想要第二行,那么更好的方法是offset
/ fetch
:
select f.*
from FindNthHighestNumber f
order by f.ProductAmount desc
offset 1
fetch first 1 row only;