小说网站 搜小说 无限网 烟雨红尘 小说爱好者 免费小说 免费小说网站

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;

posted on 2013-12-04 23:15  王小航  阅读(155)  评论(0编辑  收藏  举报

导航