How to get second highest and lowest Record in Sql server

How To get Record for Second lowest and highest record using sql server

 2nd Lowest Record
------------------------------------------------
SELECT * FROM TblTemp
WHERE
Temp_id =(SELECT max(Temp_id) FROM TblTemp
WHERE Temp_id< (SELECT max(Temp_id) FROM TblTemp))

2nd Highest record
-------------------------------------------------
SELECT * FROM TblTemp
WHERE
Temp_id = (SELECT min(Temp_id) FROM TblTemp
WHERE Temp_id > (SELECT min(Temp_id) FROM TblTemp))


2nd highest record
-----------------------------------------------
select Temp_id from TblTemp r1
where 2=(select count(*) from TblTemp r2
where r1.Temp_id <= r2.Temp_id)

4th Highest Record
-----------------------------------------------
SELECT Temp_id from TblTemp c1
WHERE 4=(SELECT count(*) from TblTemp c2
WHERE C1.Temp_id >= C2.Temp_id )

4th Lowest Record
-----------------------------------------------

SELECT Temp_id from TblTemp c1
WHERE 4=(SELECT count(*) from TblTemp c2
WHERE C1.Temp_id <= C2.Temp_id)

Ebook Download
View all
milton
Read by 0 people
Download Now!
Learn
View all