EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ------- ---------- --------- ---------- ---------- ---------- ---------- ---------- 7900 JAMES CLERK 7698 03-12月-81 950 30 7902 FORD ANALYST 7566 03-12月-81 3000 20 7934 MILLER CLERK 7782 23-1月 -82 1300 10
------解决方案-------------------- 分析函数
SQL code
select *
from
(select t.*,row_number() over(partition by 部门号 order by 工资) rn
from table t)
where rn<=3
------解决方案-------------------- FYI: 问题10 http://topic.csdn.net/u/20081002/00/f8d90ba2-e2bb-412a-a0c5-1b6d518fc22a.html
------解决方案--------------------
SQL code
SELECT *
FROM (SELECT EID,
ENAME,
DEPTNO,
SAL,
ROW_NUMBER() OVER(PARTITION BY DEPTNO ORDER BY SAL DESC) RN
FROM EMP)
WHERE RN <= 3;