none
something urgent RRS feed

Answers

  • You could select all of the data and then find the 2nd and 3rd in your code, but I assume you are looking for an SQL statement to do this at the database.

    If you are using SQL Server, here is a way to do it that can easily be adapted for other ranges.  Other database servers may or may not support this syntax or a similar syntax.  (This does not robustly address cases where two employees have the same salary.  It will need to be modified if that is important to you.)

    SELECT empname, empsalary
    FROM
    (
    SELECT ROW_NUMBER() OVER (ORDER BY empsalary DESC) rownum, empname, empsalary
    FROM employee
    ) inr
    WHERE inr.rownum BETWEEN 2 AND 3
    ORDER BY empsalary DESC

    To get an answer better targeted to your scenario, please provide more information.

     

    Thursday, April 1, 2010 10:42 PM