If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Query for Top X%

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-26-12, 07:03
EMoscosoCam EMoscosoCam is offline
Registered User
 
Join Date: Mar 2003
Posts: 144
Question Query for Top X%

Hello

(Using Oracle 9i)

I have a resultset that has the structure (#ProductCode, Sales). I would like to know how to get the Products that are within the 80% of the sales total.


Thanks a lot.
Reply With Quote
  #2 (permalink)  
Old 01-26-12, 10:13
flyboy flyboy is offline
Registered User
 
Join Date: Mar 2007
Posts: 546
Hello,
I am just curious what tool is supposed to transform the source "resultset" to required result set. Note, that "Oracle" is quite broad term - database, Forms, Reports, apex, whatever else ...

Anyway, in pure SQL, you would these three steps (as you did not post any code, I will not do so too):
1) If productcode is not unique, aggregate by it firstly to get total sales for each one.
2) Use SUM function in its analytic form to get cumulative sales sum (ordered by total sum desc) and total sales sum.
3) Filter those rows which cumulative sum/total sum is less than 80% (shall the product exceeding 80% be present too?)
Alternatively you may compute the least contributing products (ordered by total sum asc) and filter those products which cumulative sum/total sum is over 20%.

For detailed description of analytic functions, please consult SQL Language Reference for your Oracle version. It is available with other Oracle documentation books e.g. online on http://tahiti.oracle.com/

Last edited by flyboy; 01-26-12 at 10:14. Reason: cumulative has only single 'm'
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On