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 2005 Forums
 Transact-SQL (2005)
 Tricky select with an AVG

Author  Topic 

apatel32
Starting Member

2 Posts

Posted - 2008-05-22 : 17:32:38
I don't even know if this is possible, but I need to find a way to do the following:

I have a select statement that returns the the Top (x) scores from a table called Rounds. The number of rows (x) will vary based on another calculation that I have, in this example I used 3.

SELECT TOP (3) Scores
FROM Rounds AS Rounds_1
WHERE (UserID = 'testuser')

I need to take the 3 values from this example, and calculate the AVERAGE. How do I do that?

Thank you.


SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-22 : 17:52:26
SELECT AVG(Score)
FROM
(SELECT TOP 3 SCORE FROM Rounds ORDER BY Score DESC) AS d



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

apatel32
Starting Member

2 Posts

Posted - 2008-05-22 : 19:38:06
Peso, that worked. Thank you.
Go to Top of Page
   

- Advertisement -