Abdullah Abdullah - 1 year ago 33
SQL Question

Show employees who earn more

I want to get a cursor which shows me the 3 employees who earn more. Here is the table, SOU means salary.

Nombre ‚ĒźNulo? Tipo
----------------------------------------- -------- ----------------------------
CODI_EMPL NOT NULL NUMBER(3)
NOM_EMPL NOT NULL VARCHAR2(20)
COGNOM_EMPL NOT NULL VARCHAR2(50)
SOU NOT NULL NUMBER(8,2)
NOM_DPT VARCHAR2(20)
CIUTAT_DPT VARCHAR2(20)
CODI_PROJ NUMBER(3)


So I want to create a procedure which stores the three employees who earn more, obviously with CURSOR. I do not know here to start, i do not know who the query should be... Thanks in advance!

Answer Source

I dont think you need cursor for this. Try this query

SELECT  * FROM 
(
SELECT * FROM Table
ORDER BY SOU desc
)
WHERE rownum <= 3
ORDER BY SOU;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download