Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
T_ID T_NAME BPS_GRADE SALARY
1 IMRAN 17 30000
2 AHMAD 18 35000
3 KAMRAAN 17 32000
4 ASIF 19 40000
5 TOFEEQ 18 33000
Posted
Updated 11-Nov-15 16:41pm
v4
Comments
Dave Kreskowiak 11-Nov-15 13:40pm    
And the question would be .......??

You really don't expect us to do your homework for you, right?

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 
ROW_NUMBER[^] is that what you're looking for.

SQL
SELECT RowNo, T_ID, T_NAME, BPS_GRADE, SALARY
FROM (
    SELECT T_ID, T_NAME, BPS_GRADE, SALARY, ROW_NUMBER OVER(ORDER BY SALARY DESC) AS RowNo
    FROM YourTableName
) AS T 
WHERE RowNo IN (2,3)


See the other ranking functions[^] too.
 
Share this answer
 
v2
Try Below Example :-

---FIND SECONDMAXSAL SALARY

SQL
SELECT MAX(ESAL)AS SECONDMAXSAL FROM EMP1 WHERE ESAL NOT IN(SELECT MAX(ESAL) FROM EMP1)



--FIND THIRDMAXSAL SALARY

SQL
SELECT MIN(ESAL)AS THIRDMAXSAL FROM EMP1 WHERE ESAL IN(SELECT TOP 3 (ESAL) FROM EMP1 ORDER BY ESAL DESC)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900