I want second largest value. I can get first largest by using max(field name) but how i can get 2nd largest.Is there any custom code. I am new so any help greatly appreciated. Thanks!
I want it in SSRS
I want second largest value. I can get first largest by using max(field name) but how i can get 2nd largest.Is there any custom code. I am new so any help greatly appreciated. Thanks!
I want it in SSRS
ORDER BY
your field DESC
, then limit the result set to 1 row, starting at the 2nd row:
SELECT field FROM TABLE ORDER BY field DESC LIMIT 1, 1;
(This is MySQL syntax, your engine may vary.)
This is messy but It should work:
SELECT TOP 1
[column]
FROM [table]
WHERE [column] <>
(
Select top 1
[column]
from [table]
order by [column] DESC
)
ORDER BY [column] DESC
If this is in a procedure and you dont care about doing 2 queries this looks a bit neater:
DECLARE @MAX INT
SELECT TOP 1 @MAX = MAX([COLUMN]) from [table] order by [COLUMN] desc
SELECT TOP 1 [COLUMN] FROM [TABLE] WHERE [COLUMN] <> @mAX order by [COLUMN] desc