banner
RustyNail

RustyNail

coder. 【blog】https://rustynail.me 【nostr】wss://ts.relays.world/ wss://relays.world/nostr

Do not use order by to get the x-th largest xx.

No need to order by to get the xth largest xx, group according to requirements -> the result is the group with x items.

select s.emp_no, s.salary, e.last_name, e.first_name from salaries s join employees e on s.emp_no=e.emp_no
and s.to_date='9999-01-01'
and s.emp_no=(select s1.emp_no from salaries s1 join salaries s2 on s1.salary<=s2.salary
              and s1.to_date='9999-01-01' and s2.to_date='9999-01-01'
              group by s1.emp_no having count(1) = 2);
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.