Hi,
Please check the below code.
SELECT * FROM (SELECT RowNumber = ROW_NUMBER() OVER (ORDER BY c.TableColumn_PK ASC),c.*
FROM TableName c) AS CD WHERE RowNumber = ((SELECT COUNT(*) FROM TableName)-1)
Just replace "TableColumn_PK" with your primary key and "TableName" with your table name.
I tested it. It will work fine.
Cheers....
Update: There are a lot of solutions too for this. Try to find out others.
Update:
As you posted an answer by stating that you are using sql server and you want the date difference. So, please use the code given below.
DECLARE @VAR TABLE (KeyID BIGINT IDENTITY(1,1),RANK BIGINT,LastTwoDates DATETIME)
INSERT INTO @VAR
SELECT TOP(2) RANK() OVER (ORDER BY dLastLogindate) AS RANK, dLastLogindate
FROM tbUS_Recruiter
ORDER BY RANK DESC
IF ((SELECT COUNT(*) FROM @VAR) = 2)
BEGIN
SELECT DATEDIFF(DAY,(SELECT LastTwoDates FROM @VAR WHERE KeyID = 2),(SELECT LastTwoDates FROM @VAR WHERE KeyID = 1)) AS DayCount,
DATEDIFF(HOUR,(SELECT LastTwoDates FROM @VAR WHERE KeyID = 2),(SELECT LastTwoDates FROM @VAR WHERE KeyID = 1)) AS HourCount,
DATEDIFF(MINUTE,(SELECT LastTwoDates FROM @VAR WHERE KeyID = 2),(SELECT LastTwoDates FROM @VAR WHERE KeyID = 1)) AS MinutesCount,
DATEDIFF(SECOND,(SELECT LastTwoDates FROM @VAR WHERE KeyID = 2),(SELECT LastTwoDates FROM @VAR WHERE KeyID = 1)) AS SecondCount
END
Just change "dLastLogindate" field into your date field and "tbUS_Recruiter" as your table name. It will work fine.
Code checked.
Cheers...