Subscribe to Subscribers
Talk to Webmaster Tony John


Forums » .NET » SQL Server »

2nd maximum in numeric column


Posted Date: 08 Oct 2010      Posted By:: Rajvir Singh Mahala     Member Level: Silver    Member Rank: 1357     Points: 1   Responses: 4



i want to calculate 2nd maximum in numeric column.
Please tell me a query to find it?

Rajvir Mahala
Web Developer(Convexicon Software Solutions India Pvt. Ltd.)
+919929832202




Responses

#559849    Author: Paritosh Mohapatra      Member Level: Diamond      Member Rank: 6     Date: 08/Oct/2010   Rating: 2 out of 52 out of 5     Points: 2

Please check the following query:

SELECT MIN(marks) FROM students WHERE marks IN(SELECT TOP 2 marks FROM students ORDER BY marks DESC)


Thanks & Regards
Paritosh Mohapatra
Microsoft MVP (ASP.Net/IIS)
DotNetSpider MVM



 
#559917    Author: Durva      Member Level: Gold      Member Rank: 841     Date: 09/Oct/2010   Rating: 2 out of 52 out of 5     Points: 2

select min(guessvalue) from ItemGuess
where guessvalue in (select top 2 guessvalue from ItemGuess
order by guessvalue desc)



 
#560092    Author: hemant      Member Level: Silver      Member Rank: 1268     Date: 10/Oct/2010   Rating: 2 out of 52 out of 5     Points: 3

method 1
SELECT TOP 1 no FROM (SELECT TOP 2 no FROM tbl ORDER BY no DESC) a ORDER BY no

method 2
SELECT MIN(no) FROM tbl WHERE no IN(SELECT DISTINCT TOP 2 no FROM tbl ORDER BY no DESC)

in first method it will select the top most record out of 2 values and in the 2nd one it will select the last one among 2 values.
you can change the TOP 2 by TOP 3 or 4 if you want to select 3rd or 4th highest value.

thanks
HEMANT GUPTA






 
#560159    Author: Rajvir Singh Mahala      Member Level: Silver      Member Rank: 1357     Date: 11/Oct/2010   Rating: 2 out of 52 out of 5     Points: 0

Thanks to all..................

Rajvir Mahala
Web Developer(Convexicon Software Solutions India Pvt. Ltd.)
+919929832202



 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Pivot ( Show Cross tabular format data)
Previous : Reg sqlserver installation
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.