--Delete the original table: Drop table emp;--CREATE table empcreate table emp ( deptno number, ename varchar2 (), Sal number );-- Insert data--Department 1 Employee information INSERT into EMP values (1, ' King Hee 1 ', 15000); INSERT into EMP values (1, ' King Hee 2 ', "); INSERT into EMP values (1, ' Wang Hee 3 ', 115000); INSERT into EMP values (1, ' King Hee 4 ', 12300);--Department 2 employee information INSERT into EMP values (2, ' king haha ', 14300); INSERT INTO EMP VALUES (2, ' King hehe ', 16300); INSERT into EMP values (2, ' Wang Yu ', 11300); INSERT into EMP values (2, ' King Big ', 10300); select * FROM emp;-- Select the top 3 highest wage people for each department select * from (select Deptno,ename,sal, row_number () over ( partition by Deptno ORDER by SAL (DESC) rn from emp ) where rn<=3;
Run as follows:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Oracle Implementation query A detailed example of basic information for employees in each department