top 10 PERCENT avg( CPS)


Following my query how can I do this...
This is what I have:
SELECT      top 10 PERCENT CPS
FROM          my table
my joins
WHERE                  my conditions
ORDER BY CPS DESC

This is what I want...>>>
SELECT      top 10 PERCENT avg( CPS)
FROM          my table
my joins
WHERE                  my conditions
ORDER BY CPS DESC
LVL 21
pinaldaveAsked:
Who is Participating?
 
Anthony PerkinsCommented:
AVG will give you just one value, so TOP 10 PERCENT is meaningless.  Unless you mean:

Select AVG(CPS)
From (Select TOP 10 PERCENT CPS
          From orders
          Order by CPS desc) a
0
 
pinaldaveAuthor Commented:
I will answer you tomorrow after I go to office...
I think your suggestion looks good... that is what I may wanted...
Thank you more tomorrow.
0
 
geotigerCommented:
With the avg, you need to have group by such as

SELECT top 10 percent cps
  FROM (SELECT avg(cps) as cps
          FROM your_table
      GROUP BY department)

That is you will get the departments with  average CPS among their people in the top 10 percentile.
0
 
pinaldaveAuthor Commented:
Thank you alll but somehow acperkins answer is what I was looking for. I might have not explained well what I may needed, but after running query and also verifing using good ol' calculator it brings correct answer.
Regards,
0
 
Anthony PerkinsCommented:
>>With the avg, you need to have group by such as<<
Nope.  No Group By required.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.