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 |
bogey
Posting Yak Master
166 Posts |
Posted - 2012-03-20 : 10:50:12
|
I'm trying to using the over (partition) in sql and i'm just not getting the results i want. Here is what my data looks like.LAST_NAME game1 TEAM_NO WEEK_NOJohn 192 1 1dan-G 189 1 1dan-G 221 1 2John 178 1 2I need to find the max game of each team for the week but i need to include the lastname in the resultsResults should look likeLast_Name Game1 Team_no Week_noJohn 192 1 1dan-G 221 1 2 |
|
X002548
Not Just a Number
15586 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-20 : 15:29:20
|
[code]SELECT Last_Name, Game1, Team_no, Week_noFROM(SELECT Last_Name, Game1, Team_no, Week_no,row_number() over (partition by WEEK_NO order by game1 DESC)AS RnFROM table)tWHERE Rn=1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
bogey
Posting Yak Master
166 Posts |
Posted - 2012-03-21 : 09:22:35
|
Thank everyone- With a little tweaking I was able to get the results I needed from both of your inputs.The query below works and pulls the necessary data. SELECT LAST_NAME, Game1, Team_no, Week_noFROM(SELECT X.LAST_NAME, A.Game1, A.Team_no, A.Week_no,row_number() over (partition by A.TEAM_NO, A.WEEK_NO order by A.game1 DESC)AS RnFROM dbo.BWLRHSTW A, dbo.BowlerPI XWHERE A.BOWLER_NO = X.BOWLER_NO)t |
 |
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|
|