Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to find max round

Author  Topic 

pankaj2910
Starting Member

31 Posts

Posted - 2014-02-12 : 12:51:07
I've a table having the following fields :
state|dist|company|round
1 | 1 | 2 | 2
1 | 1 | 3 | 3
2 | 1 | 3 | 2
2 | 1 | 1 | 4
2 | 2 | 12 | 1
2 | 2 | 9 | 2
2 | 2 | 4 | 3


I want to extract the max round in the state,district with the adjacent company. please help me.

pankajrocks

pankaj2910
Starting Member

31 Posts

Posted - 2014-02-12 : 13:16:58
I want the result as :
state | district | company | round
1 | 1 | 3 | 3
2 | 1 | 1 | 4
2 | 2 | 4 | 3

pankajrocks
Go to Top of Page

maunishq
Yak Posting Veteran

71 Posts

Posted - 2014-02-12 : 15:16:20
I think this can be done using the following:
1) Rank the round column
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-13 : 07:56:55
[code]
select *
from
(
select state,dist,company,[round],dense_rank() over (partition by state,dist order by [round] desc) as seq
from table
)t
where Seq=1
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -