ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Write a query to find second highest salary of an employee?

user-image
تم إضافة السؤال من قبل Muhammad Shahid Farooq , Software Engineer, System Integrator , ForeVision Business Solutions
تاريخ النشر: 2017/03/16
Bindu Thomas
من قبل Bindu Thomas , Senior Programmer Analyst , Future Trends Establishment

select max(salary) from employees where salary < (select max(salary) from employees)

Srihari Macha
من قبل Srihari Macha , Porject Lead , Syntel Ltd

select * from emp where salary = ( select salary from (select ROW_NUMBER() over (order by salary) as 'rownum', * from emp) t -- Order employees according to salary where rownum = 2 -- Get the second highest salary )

Raghul V
من قبل Raghul V , Oracle Developer , Al Mulla Group EST

select * from employee

where salary = (select  max(salary) from employee e 

where salary<(select max(salary) from employee))

 

Qaisar Mushtaq
من قبل Qaisar Mushtaq , Senior Consultant , Systems Limitied

select *

  from (select employee_name,

               salary,

               DENSE_RANK() OVER(ORDER BY salary) sal_rank

          from employees)

 where sal_rank = 2;

 

Mustafa ALi
من قبل Mustafa ALi

Select Max(sal) from Employee where sal Not In(Select Max(sal) From Emp)

MEERAN MOHIDEEN
من قبل MEERAN MOHIDEEN , Software Engineer , C-Square Info Solutions Pvt Ltd

WITH query_a AS 

( SELECT DENSE_RANK() OVER(ORDER BY sal DESC) sal_rank,

             employee, 

             sal

  FROM employee )

SELECT employee,

            sal

  FROM query_a

WHERE sal_rank = 2;

 

PRASAD BAGAREGARI
من قبل PRASAD BAGAREGARI , Sr.Associate / Senior Software Engineer , BNP PARIBAS INDIA SOLUTIONS LTD

select distinct sal from employee a where &N = ( select count(distinct(b.sal) from employee b where a.sal <= b.sal) 

Replace N by number which is requied like if its second max then N =2 and so on....

helmy yoga pranata
من قبل helmy yoga pranata , Data Analyst , Ministry of Home Affairs

other modification :

 select * from (select  rownum rank, a.* from

    (select salary from employees 

    orderby salary desc)a) where rank=2;

Hemant Kumar
من قبل Hemant Kumar , Infor WMS Admin, Functional Consultant and Support , Al Khyyat Investment

select * from (select salary,row_number() over(order by salary desc) rn from employee) where rn =2;

Aburar Yaseen
من قبل Aburar Yaseen , Sr.Developer , Cognizant Technology Solutions

select emp_id, salary

from(

     select emp_id,salary,row_number() over (order by salary desc) as salary_rank

     from emp

) sub

where salary_rank = 2 ;

Maroun Merhej
من قبل Maroun Merhej , Development Supervisor , BML Istisharat

having the empno as the key

select tb.* from (select t.*,row_number() over (partition by t.empno order by t.salary desc) salno  from employee t) tb where tb.salno=2

المزيد من الأسئلة المماثلة