select t.*
from (select t.*,
dense_rank() over (partition by country order by salary desc) as seqnum
from t
) t
where t.seqnum = 2;
现在,这样做的挑战是,如果出现平局,它可能会返回多行。如果您特别想要一行,那么:
select t.*
from (select t.*,
dense_rank() over (partition by country order by salary desc) as ranking,
row_number() over (partition by country, salary order by country) as seqnum
from t
) t
where t.ranking = 2 and seqnum = 1;
2条答案
按热度按时间euoag5mw1#
最大的问题是如何处理领带。你大概是说第二高的薪水吧。在这种情况下,你是专门寻找
dense_rank()
窗口功能:现在,这样做的挑战是,如果出现平局,它可能会返回多行。如果您特别想要一行,那么:
7cwmlq892#
比如: