Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

How to rank items starting with highest value within each group?

Total Hit ( 1527)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
create table #Test (Id int, Rank int)
go

insert #Test values (1, 1)
insert #Test values (1, 2)
insert #Test values (1, 3)
insert #Test values (2, 2)
insert #Test values (3, 1)
insert #Test values (3, 2)
insert #Test values (4, 1)
insert #Test values (4, 3)
go

/*
Id Rank
-- ----
1 3
1 2
1 1
4 3
4 1
2 2
3 2
3 1

*/


select t1.id, t1.rank
from #test t1 join (select id, max(rank) as maxrank from #test group by id) as t2
on t1.id = t2.id
order by t2.maxrank desc, t1.id, t1.rank desc


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.