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 |
|
ganeshkumar08
Posting Yak Master
187 Posts |
Posted - 2008-06-12 : 02:57:31
|
| Hi All,select MatchID, ClubID, Max(Distance) as 'MaxDist'From dbo.TrendHALF_SECOND_POSITIONSWhere MatchID in (8,12)Group By MatchID, ClubIDHow to get the PlayerID who has max(distance),If i do Group By MatchID, ClubID,PlayerID i can get the playerID,But I need PlayerID, but PlayerID should not include in Group By clauseHow can i achieve it..ThanksGaneshSolutions are easy. Understanding the problem, now, that's the hard part |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-12 : 03:00:45
|
| Is PlayerID always having same value for a particular combination of MatchID, ClubID? If yes, you can just use any aggregate function on that field i.e MIN(PlayerID) or MAX(PlayerID). If you have more than 1 value of PlayerID for each combination of MatchID, ClubID then you need to tell whats the value of PlayerID you would be interested to get as per your business rule. |
 |
|
|
ganeshkumar08
Posting Yak Master
187 Posts |
Posted - 2008-06-12 : 04:48:58
|
| Thank You VISAKH, I got an idea and got a solution for this.With MostPassReceive(MatchID,PassingPlayerClubID,PassingPlayerID,Passcount)AS( Select MatchID,PassingPlayerClubID,PassingPlayerID,Count(PassingPlayerID) As Passcount From TrendEvents_Distribution Group By MatchID,PassingPlayerClubID,PassingPlayerID)Select P.MatchID,P.PassingPlayerClubID,dbo.fn_ResolvePlayerID(P.PassingPlayerID) As Player,PassCountFrom MostPassReceive P Where 0 = (Select Count(Distinct Passcount) From MostPassReceive C Where C.PassCount > P.PassCount And P.MatchID=C.MatchID And P.PassingPlayerClubID=C.PassingPlayerClubID )order By P.MatchID |
 |
|
|
ganeshkumar08
Posting Yak Master
187 Posts |
Posted - 2008-06-12 : 05:44:27
|
| hello Visakh, My query returns the Same Passcount for a two different players for playerclubid.Can u help me how to eliminate dupliates.I want to eliminate the record which i marked in box.The below is the result0 88 10 Celestine 310 89 20 Denny LANDZAAT 35-----------------------------------------------0 88 5 Scott PARKER 31-----------------------------------------------1 88 7 Titus BRAMBLE 661 90 30 Gavin MCCANN 482 91 46 Michael BROWN 282 88 3 Belozoglu EMRE 393 92 65 Lee BOWYER 373 88 3 Belozoglu EMRE 404 93 78 Xabi ALONSO 584 88 10 Celestine BABAYARO 405 88 3 Belozoglu EMRE 345 94 93 Phil NEVILLE 426 95 106 Paul SCHOLES 836 88 3 Belozoglu EMRE 407 88 115 Scott PARKER 407 96 124 Kevin NOLAN 297 88 112 Belozoglu EMRE 408 88 5 Scott PARKER 438 97 135 George BOATENG 389 88 5 Scott PARKER 609 9 152 Andy REID 3810 88 5 Scott PARKER 3510 98 170 Mikele LEIGERTWOOD 3511 88 3 Belozoglu EMRE 3911 99 179 Joey BARTON 3912 1 190 Francesc FABREGAS 7512 88 111 Nolberto SOLANO 38---------------------------------------------12 88 8 Nicky BUTT 38---------------------------------------------13 100 212 Sean DAVIS 3613 88 111 Nolberto SOLANO 6214 88 202 Emre BELOZOGLU 5614 101 224 John OSTER 4116 88 8 Nicky BUTT 3916 102 255 John TERRY 6417 88 10 Celestine BABAYARO 4117 103 263 Gavin MAHON 2718 88 111 Nolberto SOLANO 4318 104 282 Tom HUDDLESTONE 5019 96 129 El-Hadji DIOUF 4119 88 8 Nicky BUTT 3820 94 93 Phil NEVILLE 4020 88 8 Nicky BUTT 5721 88 202 Emre BELOZOGLU 3421 95 106 Paul SCHOLES 6122 88 188 Kieron DYER 5622 104 282 Tom HUDDLESTONE 4723 92 303 Nigel QUASHIE 3523 88 111 Nolberto SOLANO 5724 88 188 Kieron DYER 3924 90 29 Gareth BARRY 4125 88 8 Nicky BUTT 4325 91 46 Michael BROWN 4626 93 75 Steven GERRARD 4826 88 13 Steven TAYLOR 4827 89 20 Denny LANDZAAT 3527 88 5 Scott PARKER 2428 88 111 Nolberto SOLANO 5828 97 135 George BOATENG 3729 9 149 Luke YOUNG 3029 88 5 Scott PARKER 6130 99 345 Michael JOHNSON 3730 88 1 Stephen CARR 6431 88 1 Stephen CARR 4231 1 190 Francesc FABREGAS 5732 102 353 John MIKEL 5232 88 3 Belozoglu EMRE 4633 88 188 Kieron DYER 5033 101 224 John OSTER 2934 88 111 Nolberto SOLANO 5334 5 233 Tugay KERIMOGLU 3335 88 8 Nicky BUTT 5935 103 270 Adrian MARIAPPA 2936 5 233 Tugay KERIMOGLU 7036 88 8 Nicky BUTT 5537 9 154 Matt HOLLAND 4537 95 492 John O'SHEA 6538 102 351 Wayne BRIDGE 5338 91 278 Danny MURPHY 4639 1 190 Francesc FABREGAS 6939 92 232 Lucas NEILL 5240 114 279 Hossam GHALY 2640 113 518 Fabrice MUAMBA 2941 115 533 Velice SUMULIKOSKI 6241 116 249 Frank LAMPARD 5243 5 237 David BENTLEY 3843 94 89 Mikel ARTETA 2944 95 292 Ryan GIGGS 3944 1 190 Francesc 6145 94 93 Phil NEVILLE 5445 96 126 Gary SPEED 30 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-12 : 05:58:32
|
May be this:-;With MostPassReceive(MatchID,PassingPlayerClubID,PassingPlayerID,Passcount)AS(Select MatchID,PassingPlayerClubID,PassingPlayerID,Count(PassingPlayerID) As PasscountFrom TrendEvents_DistributionGroup By MatchID,PassingPlayerClubID,PassingPlayerID)SELECT * FROM(Select ROW_NUMBER() OVER(PARTITION BY P.MatchID,P.PassingPlayerClubID ORDER BY P.MatchID) AS RowNo,P.MatchID,P.PassingPlayerClubID,dbo.fn_ResolvePlayerID(P.PassingPlayerID) As Player,PassCountFrom MostPassReceive P Where 0 = (Select Count(Distinct Passcount) From MostPassReceive C Where C.PassCount > P.PassCount And P.MatchID=C.MatchID And P.PassingPlayerClubID=C.PassingPlayerClubID))tmpWHERE tmp.RowNo =1order By tmp.MatchID |
 |
|
|
ganeshkumar08
Posting Yak Master
187 Posts |
Posted - 2008-06-12 : 06:03:21
|
| Thanks a lot.... |
 |
|
|
|
|
|
|
|