
April 19th, 2004, 12:50 PM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
ORDER BY Average of values in subtable
The situation is that I have two tables, one "T_Team" and one "T_Player". T_Team contains a team name and index value, and T_Player contains a foreign key representing the team index, a player name, and a score.
What I'm trying to do is create a select statement that will retrieve all the team names and order them by the average score for that team. The following obviously won't work because the nested select has no reference to the higher level table:
SELECT T.Name
FROM T_Team T
ORDER BY AVG(
SELECT P.Score
FROM T_Player P
WHERE P.FK_TeamIndex = T.Index
)
How does one get around this though?
K.
|