SELECTing top N rows without ROWNUM?

后端 未结 5 1254
遇见更好的自我
遇见更好的自我 2020-12-18 09:19

I hope you can help me with my homework :)

We need to build a query that outputs the top N best paid employees.

My version works perfectly fine.
For exam

5条回答
  •  长情又很酷
    2020-12-18 09:32

    When you use count(distinct ), equal ranking top salaries will be treated as tie ranks.

    select NAME, SALARY
    from  STAFF STAFF1
    where 3 >= ( select count(distinct STAFF2.SALARY) RANK
                   from STAFF STAFF2
                  where STAFF2.SALARY >= STAFF1.SALARY)
    

提交回复
热议问题