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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Aggregate select using row criteria

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2000-10-18 : 18:58:29
Mike writes "This question is easier to ask by example.
Say I have the following abbreviated table:
Player Year HomeRuns
Babe Ruth 1920 26
Babe Ruth 1921 58
Babe Ruth 1922 48
Babe Ruth 1923 44
Babe Ruth 1924 52
Willie Mays 1950 44
Willie Mays 1951 48
Willie Mays 1952 56
Willie Mays 1953 39
Willie Mays 1954 45
Micky Mantle 1960 51
Micky Mantle 1960 58
Micky Mantle 1960 41
Micky Mantle 1960 38
Micky Mantle 1960 50
I want to know the average home runs for each player during his two(n) most prolific years. For Example, Babe had 58 in '21 and 51 in '24 for an average of 55. I have figured out a way to do this in Oracle due to the peculiarities of it's views but I would like to know how to do it using straight SQL."
   

- Advertisement -