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 |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-08-11 : 08:39:37
|
Eric writes "Please help me with an SQL equation that will look at a large series of numbers (hundreds) and return the average of the largest 40 numbers in that series. Thanks for the help! " |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2006-08-11 : 08:43:21
|
Hmmmm. Kinda smells like homework, but I'll bite:SELECT Avg(num) FROM (SELECT TOP 40 num FROM myTable ORDER BY num DESC) aDepending on how you want to handle duplicate values, you may need to use:SELECT Avg(num) FROM (SELECT TOP 40 WITH TIES num FROM myTable ORDER BY num DESC) aOr, if you want the average of the distinct values:SELECT Avg(num) FROM (SELECT DISTINCT TOP 40 num FROM myTable ORDER BY num DESC) a |
 |
|
druer
Constraint Violating Yak Guru
314 Posts |
Posted - 2006-08-11 : 08:43:56
|
select avg(select top 40 field_value from table order by field_value DESC) as Avg_For_Top_40Hope it helps,DaltonBlessings aren't so much a matter of "if they come" but "are you noticing them." |
 |
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2006-08-11 : 11:40:14
|
Kapow!For fast help, follow this link:http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxLearn SQLhttp://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
|
|