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
 General SQL Server Forums
 New to SQL Server Programming
 Show top Percentile

Author  Topic 

fengfeng
Yak Posting Veteran

64 Posts

Posted - 2011-05-10 : 14:28:00
I have the following query:


SELECT order.name, SUM(vz.volume),SUM(vz.sales),SUM(vz.post_volume),SUM(vz.post_sales), SUM(vz.sales)/SUM(vz.volume) AS 'Ratio'

FROM vz_delivery vz, vz_order ORDER

WHERE vz.order_id = order.id

AND DATE BETWEEN '2010-01-01' AND ' 2011-04-30'

GROUP BY order.name



How can I SHOW the results of the top 20% of results BY Ratio? So the top 20 highest ratios?


robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-05-10 : 14:31:30
SELECT TOP 20 PERCENT order.name, SUM(vz.volume),SUM(vz.sales),SUM(vz.post_volume),SUM(vz.post_sales), SUM(vz.sales)/SUM(vz.volume) AS 'Ratio'
FROM vz_delivery vz, vz_order ORDER
WHERE vz.order_id = order.id
AND DATE BETWEEN '2010-01-01' AND ' 2011-04-30'
GROUP BY order.name
ORDER BY Ratio DESC
Go to Top of Page
   

- Advertisement -