Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SQL query - AVG TOP 10

Posted on 2008-10-30
3
1,952 Views
Last Modified: 2009-03-17
Hi all,
How do I use a avg statement in conjunction with a top selection? Like:

select avg
(select top 10 column1
from table1
order by column1 desc)

Thanks!
0
Comment
Question by:avdvyver1
3 Comments
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 22839060
Select * from emp where sal > (select avg(sal) from emp);
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 22839086
select avg (Column1)
from
(select top 10 column1
from table1
order by column1 desc)a
0
 
LVL 3

Expert Comment

by:TechSinger
ID: 22839117
Try this.

select avg(t1.column1)
from (select top 10 t2.column1 
from table1 t2
order by t2.column1 desc) t1

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question