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.
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 | 3I 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 | 3pankajrocks |
 |
|
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 |
 |
|
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 seqfrom table)twhere Seq=1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|