Find the 2nd highest salary of employee data

 1.

     SELECT MAX(salary) AS second_highest_salary

     FROM employee
     WHERE salary < (SELECT MAX(salary) FROM employee);

2.   SELECT salary
      FROM (
            SELECT salary,
           DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk
           FROM employee
        ) t
     WHERE rnk = 2; 

3. Mysql :

        SELECT DISTINCT salary
        FROM employee
        ORDER BY salary DESC
        LIMIT 1 OFFSET 1; 

4.  SELECT DISTINCT salary
     FROM employee
     ORDER BY salary DESC
     OFFSET 1 ROWS FETCH NEXT 1 ROW ONLY; 

No comments:

Post a Comment

Most Recent posts

Copy and Modify Stages

In IBM Infosphere DataStage , both Copy Stage and Modify Stage are simple processing stages used in parallel jobs , but their purpose i...