Display top 3 sales column wise

I have two tables as below
AREA (area_code, area_name)
MONTHLY_SALES (area_code, isbn, book_name, qty, sales_amount)
I want to display the output of top 3 sales columnwise as below.
AREA_NAME  Top 1st (ISBN) Top 1st (BOOK_NAME)  Top 1st (QTY)     Top 2nd (ISBN)     Top 2nd (BOOK_NAME) Top 2nd (QTY)     Top 3rd (ISBN)  Top 3rd (BOOK_NAME)     Top 3rd (QTY)Can anyone help to solve this?

something like this,..
WITH area AS (SELECT '01' area_code ,'abc' area_name FROM dual UNION ALL
                                                 SELECT '02' ,'bcd' FROM dual  ),
MONTHLY_SALES  AS (SELECT '01' area_code,9888774452 isbn,'IS1BK' book_name ,30 qty ,1234 sales_amount  FROM dual UNION ALL
                                                                        SELECT '01' ,9855123365,'IS2BK',20,2345 FROM dual UNION ALL
                                                                     SELECT '01' ,9877112254,'IS3BK',10,3456  FROM dual UNION ALL
                                                             SELECT  '02' ,9788554412,'IS4BK',72,4566  FROM dual UNION ALL
                                                             SELECT  '02' ,6622144554,'IS4BK',62,4566  FROM dual  UNION ALL
                                                             SELECT  '02' ,9711223365,'IS4BK',52,4566  FROM dual  )
SELECT "Top 1st (ISBN)","Top 1st (BOOK_NAME)","Top 1st (QTY)","Top 2nd (ISBN)","Top 2nd (BOOK_NAME)", "Top 2nd (QTY)"     ,"Top 3rd (ISBN)" , " Top 3rd (BOOK_NAME)","Top 3rd (QTY)"
FROM
(SELECT  area_name, isbn "Top 1st (ISBN)", book_name "Top 1st (BOOK_NAME)",qty "Top 1st (QTY)" ,lead(isbn,1) OVER (PARTITION BY area_name ORDER BY TOP_ORDER ) "Top 2nd (ISBN)" ,
                       lead(book_name,1) OVER (PARTITION BY area_name ORDER BY TOP_ORDER)"Top 2nd (BOOK_NAME)",lead(qty,1)  OVER (PARTITION BY area_name ORDER BY TOP_ORDER ) "Top 2nd (QTY)"     ,
                       lead(isbn,2) OVER (PARTITION BY area_name ORDER BY TOP_ORDER) "Top 3rd (ISBN)" , lead(book_name,2) OVER (PARTITION BY area_name ORDER BY  TOP_ORDER ) " Top 3rd (BOOK_NAME)",
                       lead(qty,2) OVER (PARTITION BY area_name ORDER BY TOP_ORDER )     "Top 3rd (QTY)" ,TOP_ORDER  FROM
(SELECT area_name, isbn, book_name,qty,  row_number () OVER (PARTITION BY area_name ORDER BY qty DESC) "TOP_ORDER"
FROM area a, monthly_sales m
WHERE  a.area_code=m.area_code ))
WHERE TOP_ORDER=1;
Output
Top 1st (ISBN)     Top 1st (BOOK_NAME)     Top 1st (QTY)     Top 2nd (ISBN)     Top 2nd (BOOK_NAME)     Top 2nd (QTY)     Top 3rd (ISBN)      Top 3rd (BOOK_NAME)     Top 3rd (QTY)
9888774452     IS1BK     30     9855123365     IS2BK     20     9877112254     IS3BK     10
9788554412     IS4BK     72     6622144554     IS4BK     62     9711223365     IS4BK     52

Similar Messages

  • Display DOT separated value column wise

    I have one column name Department.
    Department have value as Department =Department.Section.SubSection as take example
    Department clunm value given below:
    IT Development and User Services
    IT Projects(No dot)IT Development and User Services.IT User Services.IT Quality   (only one Dot)
    IT Development and User Services.In-House & Distributed Applications  (only one Dot)
    Infrastructure Services.System Support.Database Support (max two Dot)
    above value separted by . "Dot",I have requirement to show if two dot data should show three section like Dep1,sec1 and Subsec 1
    also i required use where class wehr i pass any value between dot.
    Hasan Jamal Siddiqui(MCTS,MCPD,ITIL@V3),Sharepoint and EPM Consultant,TCS
    |
    | Twitter

    Hi Uri
    below is the mention example data
    IT Development and User Services(No dot)
    IT Projects(No dot)
    IT Development and User Services.IT User Services.IT Quality   (only
    one Dot)
    IT Development and User Services.In-House & Distributed Applications  (only
    one Dot)
    Infrastructure Services.System Support.Database
    Support (max two Dot)
    You can find the dot.
    Hasan Jamal Siddiqui(MCTS,MCPD,ITIL@V3),Sharepoint and EPM Consultant,TCS
    |
    | Twitter

  • Regarding: table having block stock field sales order wise

    Hi,
    I am working on report in which i have to display the block stock sales order wise ,i had used to tcode MB52 and MMBE and i was first using table MCHB and MARD ,it displays only the bocked stock ,but when i click on  special stocks icon in tcode MB52 n execute it the qty displayed in that is not being able to be displayed in the tables MARD n MCHB.
    right now i am using table MSKA and varifying it with MB52 tcode.
    PLZZ HELP ME OUT BY telling me which table to be used for displaying the block sales order wise.
    Edited by: ric .s on Mar 6, 2008 11:19 AM

    Hi,
    Try out this.
    DATA: is_object                TYPE sibflporb,
                it_relation_options TYPE obl_t_relt,
                is_relation_options TYPE obl_s_rolt,
               gt_links                    TYPE obl_t_link.
               is_object-instid    = <sales order number with leading zeros>.
               is_object-typeid   = 'BUS2032'.
               is_object-catid     = 'BO'.
    *u201Ddocument relation
    is_relation_options-sign      = 'I'.
    is_relation_options-option   = 'EQ'.
    is_relation_options-low        = 'ATTA'.
    APPEND is_relation_options TO it_relation_options.
    TRY.
        CALL METHOD cl_binary_relation=>read_links
          EXPORTING
            is_object           = is_object
            it_relation_options = it_relation_options
          IMPORTING
            et_links            = gt_links.
    ENDTRY.
    GT_LINKS should be filled if sales order has attachment.
    Regards,
    Sudhakar

  • Reagrding :  block stock sales order wise

    Hi,
    I am working on report in which i have to display the block stock sales order wise ,i had used to tcode MB52 and MMBE and i was first using table MCHB and MARD ,it displays only the bocked stock ,but when i click on  special stocks icon in tcode MB52 n execute it the qty displayed in that is not being able to be displayed in the tables MARD n MCHB.
    right now i am using table MSKA and varifying it with tcode mb52.
    PLZZ HELP ME OUT BY telling me which table to be used for displaying the block sales order wise.
    Edited by: ric .s on Mar 6, 2008 11:18 AM

    Blocks can be of different types and at different levels..
    All header level sales order blocks can be seen in VBUK and item level at VBUP.
    For eg : VBUP-FSSTA - Billing block status for items and
                VBUP-LSSTA - Delivery block
    Also look at the following fields of VBUK :
    FSSTK     -Overall billing block status
    LSSTK_-Overall delivery block status
    SPSTG     -Overall blocked status

  • Display data column wise in alv

    my problem is i want to display data in column wise in alv grid display
    for example it will display
    Name1    Amount
    GTS       12000
    TSL        8970
    MJB        4678
    but i want like:
    GTS    TSL    MJB
    12000 8970  4678
    Edited by: jadav_avani on Nov 15, 2010 8:33 AM
    Moderator Message: Search for available information.
    Edited by: kishan P on Nov 15, 2010 1:50 PM

    my problem is i want to display data in column wise in alv grid display
    for example it will display
    Name1    Amount
    GTS       12000
    TSL        8970
    MJB        4678
    but i want like:
    GTS    TSL    MJB
    12000 8970  4678
    Edited by: jadav_avani on Nov 15, 2010 8:33 AM
    Moderator Message: Search for available information.
    Edited by: kishan P on Nov 15, 2010 1:50 PM

  • How to display the value of a column in a chart at the top of each column

    How to display the value of each column in a chart at the top of each column?

    Like this?
    Done using chart Inspector.
    For details, see Chapter 7,  Creating Charts from Numerical Data in the Numbers '09 User Guide. The guide may be downloaded via the Help menu in Numbers.
    Regards,
    Barry

  • How to display top 2 countries in 2 columns in Report Designer

    Hello Gurus ,
    I have a requirement where top 2 countries has to be displayed in two different columns in Report Designer.
    is there are way to do that, i tried many differetn ways but was not successfull, apart from creating text variables and writing customer exit.
    I appreciate your help
    Thanks,
    Kumar

    Hi,
    I am not sure what version you are, from version 9.3 I think there is a "Top" function, just highlight the row, tick the option for "Top", set the number and the column
    Failing that if you need to use rank could you not hide the column.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Display data as rowwise (horizontally ) instead of column wise ( verticaly)

    I am displaying the data from milti select prompt of BI Answers in BIP report.
    The data from the table is displayed as
    Table structure :
    Company. Unit name f_company_._unit_e
    output :
    unit1
    unit2
    unit3
    I want output as unit1, unit2, unit3
    Thanks
    Aj
    Edited by: user9031011 on May 11, 2010 7:35 AM
    Edited by: user9031011 on May 11, 2010 7:46 AM

    Hi Aj,
    First of all, correct me my previous solution.
    1. If you want to print the units in column wise i.e. if the for loop is in a table and you want each unit to be displayed in a separate columns side by side then in one of the table cell (i.e. in the for-each field of the cell) keep below code,
    <?for-each@column:ROW?> <?EMPNO?> <?end for-each?>
    2. If you want to print as a normal text (with out table) then use
    <?for-each@inlines:ROW?> <?EMPNO?> <?end for-each?>
    Second, to modify the form field,
    Select the for-each form field, go to to Add-Ins -> Tools -> Field Browser , then double click the for-each and in the edit box change the text according to your requirement, then click 'Update' button.
    You can also place that for-each condition out side(i mean with out form field)

  • How to display top 10 values in a Webi report?

    Hi,
    I have the following requirement.
    If the report contains 'State' and 'Revenue' columns, I need to display top 10 cities with highest revenue and the revenue of the remaining cities can be summed together and should be available in a separate cell.
    I tried several formulae to achieve the requirement but was unsuccessful.
    I created a variable using the formula: '= If (Rank(<State> ,<Sales revenue>)>10 ) Then Sum(<Sales revenue>) Else 0' and added it as a column in the report. This provides the required results.
    When I add this variable as a column in the report, it displays 0 for the first top 10 values and only displays the remaining values. After that we can apply the Sum on this column to get the sum of the remaining (Other) sales revenue excluding top 10 values. However I cannot display this sum in a separate cell.
    Please provide some suggestions on this.
    Regards,
    Aditya Joshi

    Hi Aditya,
    Could you please try the following solutions to resolve the issue.
    Solution1:
    In Oracle, there is a function called: RANK() OVER (PARTITION BY () ORDER BY ()) which can be used to define an object at Universe level to return a rank position when used in a report. If you can check with your DBA - there is a similar function available for SQL Server. It should be RANK() OVER (ORDER BY colname) AS () FROM.
    Solution2:
    Or you can also try returning all rows in query, apply sort at report level & apply alerter to highlight the top 10 values.
    Regards,
    Sarbhjeet Kaur

  • Sale order wise stock and Issuance of external procurement material.

    Transaction : ME21N and MIGO                                           
    Dear SDNites,                                             
    When i make a account assigned PO(with ref to sale order), then material comes and goes directly for consumption.                              
    I want that when the material comes after 105 movt., it should go to un-restricted stock and i can see in mmbe(or any other transaction) how much qty. has come against 
    which sale order, so that i can issue material also sale order wise by movement 231                                                                  
    Pls. help as to how to go about it.                                    
    Rgds.,                                                    Parag                                                     09815999582.

    Hi,
    When you are trying to create PO with reference to SO what is the item category used in SO, Use item category as "TAB" then SO will generate a Purchase Requisition. Convert this Purchase requisition in to Purchase Order, account assignment will be copied as "E Individual Customer stock" Sales order and Cost element will populate from PR.
    When you post the GR for above PO, the stock is managed as Special Stock indicator "E" sales order stock, in MMBE also it displays as SO stock.At the time of GR value is booked to SO and stock will be shown in MMBE.
    This stock is reserve for particular SO against which you have procured, but you can transfer post the same from SO stock to your OWN stock
    Hope this clarifies,
    Thanks & Regards,
    Sridhar

  • Storing the Material Sale Order Wise

    In our Scenario PO is made Sale Order wise, but when the Material is received and entered in the Stock, it become difficult to indetify the Material which has come against which SO.
    My requirement is that if the Material is received Sale Order Wise then it shud be saved in the Store Sale Order Wise and also at the same time it will be issued Sale Order wise, to keep the track of material being issued against Sale Order Wise.
    i hope i have cleared my query, any clues.....
    abhishek suppal

    Hi,
    When you are trying to create PO with reference to SO what is the item category used in SO, Use item category as "TAB" then SO will generate a Purchase Requisition. Convert this Purchase requisition in to Purchase Order, account assignment will be copied as "E Individual Customer stock" Sales order and Cost element will populate from PR.
    When you post the GR for above PO, the stock is managed as Special Stock indicator "E" sales order stock, in MMBE also it displays as SO stock.At the time of GR value is booked to SO and stock will be shown in MMBE.
    This stock is reserve for particular SO against which you have procured, but you can transfer post the same from SO stock to your OWN stock
    Hope this clarifies,
    Thanks & Regards,
    Sridhar

  • Sales order wise report

    HI friends
    I am generating a report according to sales order wise stock .
    I need a help in these
    kdauf             kdpos      shkzg        menge          
    0000001663     000010     S           10
    0000001663     000010     S           20
    0000001663  000010      S           30
    0000001663  0000020    s            10
    0000001663  00000020  s            10
    0000001663 00000020    s           10
    0000001665     000010     S           10
    Now the requirement was for everysalesorder and with respect to line item  quantity should be added
    00000001663        10          60
    00000001663        20         30
    00000001665        10         10
    the ouput should be displayed like these.

    Hi
    thanks for the reply
    0000001663     000010     S 10
    0000001663     000010     S 20
    0000001663 000010 S 30
    0000001663 0000020 s 10
    0000001663 00000020 s 10
    0000001663 00000020 s 30
    0000001663 00000020 h 20
    0000001663 00000020 h 20
    0000001665     000010     S 10
    here the requirement sales order and line item debits and credits should be added and should as like thse
    00000001663  10  60qty
    00000001663  20  10                  (s = 50 h = 40 ) s-h = 10.
    00000001665 10  10
    the report should display like these
    thanks

  • How to display the data in row wise in smartform

    Hi,
        I have to make a modification a smartform of poprinting and i want to display the row wise . At present it is displaying the  
        column wise. Actually there is a text which i want to display the data row wise.
        It is possible to display the data in row wise of the text .
    Edited by: nav009 on Oct 8, 2009 10:39 AM

    Hello ,
    I  assume that your requiremen is related to smartform.the below is the solution i suggest.
    As per my understanding of your requirement ,It's clear that as of now there is some description field which is also getting displayed along with other PO fields.
    However you would like to display the description field in a new line since the length of this field is longer than other fields as a result the data is getting scattered .
    Therefore one better option could be: since the whole data from PO would be in a loop you can display all other fields in one line type of the table as per the intial requirement and you display the description line alone in a new line type wth the desired length so that data would not be scattered and no data loss would happen.
    I assume you are aware of creating of line types for table.
    Thanks
    M.Naveen.

  • Sales group wise credit report

    Hello Experts
    Right now,we are using S_ALR_87012178 report for the report on customer open item due analysis.
    However there are a few limitations here.
    Firstly, we need Customer # (KUNNR) to be displayed along with the customer name (NAME1). Presently, only customer name is displayed.Assuming, this can be solved to a certain extent by modifying the coding with the help of an Abaper, there is another limitation.
    *We need 'Sales Group' wise split up. This 'Sales Group' NOT from CMR,but from SO. [Since, for a single customer there may be cases of multiple 'sales groups']*
    Any help/Suggestion, will surely be appreciated.
    Good day....
    Rgds
    Sumanth.Gururaj
    Consultant- SAP SD

    hi,
    exactly my mate is right in this.
    you are requested not to change the STD coding part of SAP.
    please go for new report instead of old one.
    regards,
    balajia

  • Sales employee wise report

    Hi,
    I need a report to see total sales by sales employee wise. We are using HR module and I am able to select sales employee in my sales order from the HR master. However when I run the report MCTI, I am not able to select the sales employee (no drop down available). I guess the issue is with sales employee data from sales order not getting updated in LIS. Can any one tell me the settings to update sales employee data in LIS.
    Girish

    Hi Girish,
    If you run MCTI without sales employee selection (use just sales org, distr. channel or whatever), what's the result? Do you see a bunch of zeros 00000000 under the sales employee column?
    In VPE3, are you able to find the sales ppl list under Personnel no. (with restriction to the relevant sales area)?
    Thanks for your feedback
    BR,
    Zuzana

Maybe you are looking for