TOP-N类查询

Top-N查询

--Practices_29:Write a query to display the top three earners in the EMPLOYEES table. Display their last names and salaries

方法一:

select last_name,salary     

from employees e1    

where     

  ( 

   select count(1)    

   from employees e2    

   where  e2.salary>=e1.salary 

  ) <=3  

order by salary desc;

方法二:先排序然后利用ROWNUM取需多少数据

SELECT [column_list], ROWNUM

FROM (SELECT [column_list]

FROM table

ORDER BY Top-N_column)

WHERE ROWNUM <= N;

你可能感兴趣的:(sql,查询,ebs)