Help needed in OBIEE Rank function

Hi All,
I have a request having Period, Amount,Branch code. In this i need to figure out the top N ranks (N is the user input which is populated using Presentation variable) based on the amount.
Then in the final output it should display as Top N branches with its previous period's data.
For eg: If we try to rank the amount for period=31-dec-2010. The final output should be displayed in pivot table as
*(Branchname in Pivottable section)*
* (Period to be displayed columnwise) 31-Mar-2010 30-Jun-2010 30-Sep-2010 31-Dec-2010*
Amount (Measure)
Can you guide me to achieve the above request?
Is there a way to calculate rank based on two columns?
Kindly help me.
Regards,
Bhuvan R

CREATE OR REPLACE FUNCTION fucntion_name(latA IN NUMBER, longA IN NUMBER, latB IN NUMBER, longB IN NUMBER) RETURN NUMBER
IS
pi      CONSTANT NUMBER:=3.14159;
theta NUMBER;
distX  NUMBER;
distY  NUMBER;
distZ  NUMBER;
distP  NUMBER;
BEGIN
theta :=longA - longB;
distX :=sin( latA * PI /180) * sin ( latB * PI /180) + cos ( latA * PI/180) * cos ( latB * PI/180) * cos ( theta * PI / 180);
distY :=acos(distX); --this is arc cosine
distZ :=distY * 180/PI;  --PI refers to the mathematical PI
distP :=distZ * 60 * 1.1515; --this value should be returned. Of course the intermediate variable names don't matter.
RETURN distP;
END;Edited by: Ora on May 3, 2011 11:46 PM

Similar Messages

  • Help needed in writing a function.

    I am using Oracle 11g and SQL plus. I am a complete newbie, so I need some help here in writing a function. I guess my question is more about writing the trigonometric functions within the function.
    latA, longA latB, longB // these are the four input parameters,
    theta = longA - longB
    distX = sin( latA * PI / 180) * sin ( latB * PI /180) + cos ( latA * PI/180) * cos ( latB * PI/180) * cos ( theta * PI / 180)
    distY = acos(distX) // this is arc cosine
    distZ = distY * 180 / PI // PI refers to the mathematical PI
    distP = distZ * 60 * 1.1515; // this value should be returned. Of course the intermediate variable names don't matter.
    Please help. Thanks.

    CREATE OR REPLACE FUNCTION fucntion_name(latA IN NUMBER, longA IN NUMBER, latB IN NUMBER, longB IN NUMBER) RETURN NUMBER
    IS
    pi      CONSTANT NUMBER:=3.14159;
    theta NUMBER;
    distX  NUMBER;
    distY  NUMBER;
    distZ  NUMBER;
    distP  NUMBER;
    BEGIN
    theta :=longA - longB;
    distX :=sin( latA * PI /180) * sin ( latB * PI /180) + cos ( latA * PI/180) * cos ( latB * PI/180) * cos ( theta * PI / 180);
    distY :=acos(distX); --this is arc cosine
    distZ :=distY * 180/PI;  --PI refers to the mathematical PI
    distP :=distZ * 60 * 1.1515; --this value should be returned. Of course the intermediate variable names don't matter.
    RETURN distP;
    END;Edited by: Ora on May 3, 2011 11:46 PM

  • Very urgent help needed in activating a function module

    Hello experts.
    I had a standard report and i copied into an z report. i need to change some field output , and that field is there in a standard function module.so i copied that fun module  into z fun module and stored in a new fun group. Now it is showing the error in the z fun module. include in the fun module is giving the error stating that it is not existing. please help me in coping the standard fun module correctly . please its very urgent.

    Hi,
    You should not copy a Function module alone, as it will have some dependant INLCUDES and global data in TOP include of the function group.
    SO if you want the function module copy the entire Function Group into Z function group.
    Regards,
    Sesh

  • YTD , Last year YTD help needed in OBIEE 11g

    Hi all,
    I have a report which looks this way
    Banner Name
    *Sales YTD*
    *Sales Last year YTD*
    YTD values are based on actual date of running report.
    *so ex: the report is ran on 10-feb-2013, the Sales YTD will be from
    01-Jan-2013 till 10-Feb-2013.*
    * Sales Last year YTD will be 01-Jan-2012 till 10-feb-2012.*
    I have achieved Sales YTD with my Time dimension.
    My time dimension has the data for Last year , year ago date!
    Can you please help me out on how to proceed for the Last year YTD
    calculation?
    Its helpful to share any syntax..
    Regards
    Kumar

    Hi,,
    you can use Todate Function.
    Take a Look @ this http://mkashu.blogspot.in/2013/08/obiee-model-time-series-in-obiee.html
    Regards,
    VG

  • Help Needed With "Extend Marker" Function Not Working

    I have several Clips and used the "DV Start/Stop Detect" function to find the time code breaks, which seems to work well. I've now got a clip full of Segment markers.
    The problem arises when I try to use Extent Markers "Option + `" to make subclips. When I put the play head on a subsequent marker, the Marker/Extend function is grayed out.
    Extending a marker that I have created using the M key works perfectly.
    Why can I not use the Extend function on Segment Markers?
    Any help on this is greatly appreciated. I have 30 odd clips that I need to set up segments for, and doing it manually will add hours to my workload.
    Thanks
    Gary
    Dual G5 2.5 GHz Dual Core, 2.5 GB RAM, 500 GB HDD   Mac OS X (10.4.3)   Final Cut Studio FCP 5.0.4

    Thanks for the reply.
    I am completely aware of items 1 through 3, and never Extend markers in the Timeline. Only the Viewer.
    To perform an Extend Marker and avoid headaches, load the captured clip - the one with the video icon in the Browser - into the Viewer. Then, as you scrub along in the Viewer, Option-` as needed.
    That is precisely what I am doing.
    To Extend the marker I first double click the clip to load the entire clip into the Viewer, where all the Section markers are displayed. I then check Mark>Markers>Extend and the function is grayed out. However, if I move the playhead one frame prior to the Section marker, the previous Section marker extends to the frame prior to the new play head position.
    If I do this with manually entered markers (using the M key, creating Marker 1, 2, 3.... in sequence on the Viewer timeline), then the Previous marker is extended to the frame immediately prior the the current play head position - i.e. from Marker 1 to Marker 2. I do not have to move off the Marker 2 position to be able to extend Marker 1.
    Also, simply selecting all your Markers and either dragging them to another bin (or pressing Command-U) does not produce the needed subclips?
    Of this I am also aware. I find the Command-U process just confuses the issue, creating more clips to manage (others may disagree). I prefer to simply drag the "Subclips" directly from the Main clip into a Timeline.
    Because you're doing all this to get subclips, right? Or wrong?
    If I understand your reply correctly, I think you misunderstood my problem. I have been using subclips for several years, and find them VERY useful, especially with multi-camera shoots. So, I am quite familiar with creating and extending markers.
    I just started experimenting with the Detect feature and find it works quit well (most of the time). My problem is that the Segment markers created by the Detect process, do not perform the same as manually place markers, as far as the Extend marker function is concerned, anyway.
    BTW - By using the TC display in my Panasonic PV-GS400 Camera, and sending the FCP video via Firewire to the camera, the camera displays the TC on the captured clip, which I then rename the marker to for TC reference. As long as the Date/Time on the cameras are properly synced, syncing clips in the Timeline is a breeze!!
    Anyway, to clarify, my process is as follows:
    1. Capture a clip.
    2. Display the clip in the Viewer
    3. Select "DV Start/Stop Detect" and watch as the section markers appear in the Viewer.
    4. In Viewer, place play head on the first Section marker
    5. Press the M key to Edit Marker.
    6. Change the Name of the marker to the timecode of the Marker now displayed in the Camcorder window.
    7. Use Shift-Down Arrow to move to the next Section Marker
    8. Press Option+` to Extend the previous marker - which does not work and is grayed out in the Mark>Markers>Extend menu.
    9. Back to step 5.
    This process works perfectly with manually created markers. Because the Extend works if I move the play head one frame prior to the current Section marker, this tells me there is something "special" about the Section marker that disables the Extend function, unlike a manually created marker.
    BTW - If I delete the Section marker, and create a manual marker at the same frame, the Extend marker function works again. Again, indicating that Section markers are different somehow from manual Markers.
    Hopefully, this wordy explanation of my process clarifies my problem.
    Aside: The clips are supplied to me by a customer on a 500GB FW800 drive. FCP5 was used to capture the clips from the original Tapes (which I do not have access to). I am the editor for the project.
    Thanks again for the reply. It is greatly appreciated. If there is any other info that I have missed that will help figure this out, please let me know and I will post a response a quickly as possible.
    Gary

  • Help needed in building a function

    Hello,
    I am using Oracle DB 11g.
    I am writing a function.
    create or replace function func(tab VARCHAR2) RETURN VARCHAR2 AS
    cursor c is SELECT column_name
    FROM all_tab_columns
    WHERE table_name =tab;
    begin
    //some statements
    for i in c loop
    flag=1;
    //some statements
    end loop;
    //use the same c cursor query
    if flag!=1 then
    //repeat the block inside the for loop;
    end if;
    end;
    Function works fine.
    Now once the for loop ends,what i want is if it doesn't enter the for loop, then for just for once enter the if condition for
    any column from the table and repeat the process, which i am doing inside the for loop.
    But here i am finding repetition of same query and the block of code.
    Is there any way i can avoid that?
    Thanks

    How about you start from scratch and explain the business problem you are attempting to solve. Not a portion of a technical implementation that doesn't seem to make any sense.
    Start from the beginning, no code ... just "i have a situation where i need to .... ".
    Should be a lot more productive.

  • HELP needed to write a function returning 1 record from join tables

    Hi,
    I would like to have some help to write a function so It can return 1 result.
    I post my question in the APEX Express sextion but I think it's belong here.
    Mount Points and Home Directory
    Also, can I move a thread in another forum?
    thanks
    Roseline
    Edited by: user8772975 on 2009-09-19 21:43

    ok, I think I started to understand the functions. But I still can't figured out
    CONTEXT
    We are scanning pages and images from different newspaper. All the .tif, .jpg are on DVDs.
    I'm trying to build a search page who will allow for all DVDs and All images name related to the search result. Let say I search for:
    FIGARO
    I have this SQL query and I want to make a function that will return the same thing as:
    select     
          "DOSSIER"."ID" as "DOSSIERID",
          "DOSSIER"."TITLE" as "TITLE",
          "DVD"."ID" as "DVDID",
          "DVD"."NAME" as "DVDNAME",
          "DVD"."ID_DOSSIER" as "DVD_ID_DOSSIER",
          "ELEMENTS"."ID" as "ELEMENTSID",
          "ELEMENTS"."NAME" as "ELEMENTSNAME",
          "ELEMENTS"."ID_DVD" as "ELEMENTS_ID_DVD"
    from      "DOSSIER" "DOSSIER",
               "DVD" "DVD",
               "ELEMENTS" "ELEMENTS"
    where   "DVD"."ID_DOSSIER"="DOSSIER"."ID"
    and      "ELEMENTS"."ID_DVD"="DVD"."ID"
      and       "DOSSIER"."TITLE" = :P3_SEARCH
    ORDER BY "DVD".NAMEBasiccly, We are scanning pages and images from different newspaper. All the .tif, .jpg are on DVDs.
    So we have someting like that:
    TITLE: FIGARO
    DVD:        C2008-203
    Elements: 12l10201.tif, 12l10202.tif, 12l11101.tif, 12l11102.tif, 12l11201.tif
                    12l11202.tif, 12l12101.tif, 12l12102.tif
    DVD         C2008-204
    Elements: 12l12202.tif, 12l13101.tif, 12l13102.tif, 12l13201.tif, 12l13202.tif,
                   12l14101.tif, 12l14102.tif, 12l14201.tif, 12l14202.tif, 12l15101.tif,
                   12l15102.tif, 12l15201.tif
    DVD:       C2008-205
    Elements: 12l15202.tif, 12l16101.tif, 12l16102.tif, 12l16201.tif, 12l16202.tif,
                    12m01101.tif, 12m01102.tif, 12m01201.tifBased on what people on the forum told me, I now know that I have to use Pl/SQL so I have to write a function that will return the same thing as the prvious query.
    Is that exact?
    Based on this example,
    [http://plsql-tutorial.com/plsql-functions.htm|http://plsql-tutorial.com/plsql-functions.htm]
    I would write something like:
    CREATE FUNCTION my_super_function
    RETURN VARCHAR(2000);
    IS
    details VARCHAR(2000);
    BEGIN
    select     
          "DOSSIER"."ID" as "DOSSIERID",
          "DOSSIER"."TITLE" as "TITLE",
          "DVD"."ID" as "DVDID",
          "DVD"."NAME" as "DVDNAME",
          "DVD"."ID_DOSSIER" as "DVD_ID_DOSSIER",
          "ELEMENTS"."ID" as "ELEMENTSID",
          "ELEMENTS"."NAME" as "ELEMENTSNAME",
          "ELEMENTS"."ID_DVD" as "ELEMENTS_ID_DVD"
    from      "DOSSIER" "DOSSIER",
               "DVD" "DVD",
               "ELEMENTS" "ELEMENTS"
    where   "DVD"."ID_DOSSIER"="DOSSIER"."ID"
    and      "ELEMENTS"."ID_DVD"="DVD"."ID"
      and       "DOSSIER"."TITLE" = :P3_SEARCH
    RETURN details;
    END;
    / And then, use soemthing like:
    select my_super_function("DOSSIER"."ID") from "DOSSIER" "DOSSIER" where "DOSSIER"."TITLE" = :P3_SEARCHI'm kinda of lost. I spent the last 6 hours but I think that programming is a working progress.
    Any hint would be appreciated,
    thanks
    Roseline

  • Help needed for Auto-save functionality on appraisal bsp (HAP_DOCUMENT)..

    BSP -> HAP_DOCUMENT.
    I browsed through some threads and found out the code for this, but wanted to know which page/controller method I should write in my code. This functionality is required in both Manager page and in Employee page.. Could someone help me on this, it would be very helpful...

    hi ,
    the probelm with adobe (pdf) only(.i.e. pdf attachments are damaged or something) so, check the below links to get more info regrding above error...
    http://www.computing.net/answers/windows-xp/pdf-error-acrobat-could-not-open/118542.html
    http://forum.planetpdf.com/wb/default.asp?action=9&fid=6&read=62004
    http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=6911
    thnx
    suriya

  • Help need on obiee installation

    hi all,
    i got download of obiee 10.1.3.4 from oracle webside.
    in that i got 3 subfolders named as
    1.Client_Ancillary (Oracle_Business_Intelligence_Briefing_Book_Reade,Oracle_Business_Intelligence_Open_Intelligence_Interface)
    2.Server (Oracle_Business_Intelligence)
    3.Server_Ancillary (Oracle_Business_Intelligence_Office , Oracle_Business_Intelligence_Publisher)
    I have installed server in my machine.
    and others client_ancillary and server_ancillary where to install and what is the use of those...
    can any body explain....
    now i want to install obiee on a server and i need to access these from 2-3 pcs what would be the process..

    Client_Ancillary: Programs u use when you want to run a briefing book on your laptop and have no network access
    Server_Ancillary: Programs u use when you have ms-office integration
    Normally the setup from the server folder is enough for a server installation.
    Regards
    John
    http://obiee101.blogspot.com/

  • Help needed on obiee (laptop config)

    hi all,
    I am looking to puchase a laptop. I need to install obiee in that laptop.
    can any suggest which laptop i need to purchase.
    which brand and which configuration suits for me.
    i have a look at dell inspiron 1525.
    some people are saying abt some installation errors.
    can u plzz suggest me..
    thnx in adv.
    reg.

    Check the system requirements under the [System Requirements and Supported Platforms|http://download.oracle.com/docs/cd/E10415_01/doc/nav/portal_1.htm] PDF.

  • Help needed with looping a function

    Hello experts,
    I am in a bit of a mess of ideas,
    I have a form with various search fields.
    based on the values i am passing, i am returning some values back to my form
    below is my function
    CREATE OR REPLACE function LOTTO_EROUTES.f_forecast(p_ret_num        in varchar2,
                                                        p_item_id        in number,
                                                        p_curr_date      in date,
                                                        p_expected_stock out number ,
                                                        p_actual_stock   out number,
                                                        p_inst_settled   out number,
                                                        p_prev_date      out date  ,
                                                        p_range          out number,
                                                        l_settled_avg    out number,
                                                        p_coefficient    out number                                                 
    return number is
    l_forecast_num number;
    l_curr_cdc  varchar2(6);
    l_prev_cdc varchar2(6);
    l_forecast_err varchar2(50) := 0;
    l_game_id number;
    begin
      select game_id,STOCK_COEFF_LEVEL_DAYS,IPS_SETTLED_RANGE_DAYS
      into l_game_id,p_coefficient,p_range
      from items
      where item_id =p_item_id;
    l_curr_cdc  := ltrim(rtrim(to_char(f_get_cdc_num(p_curr_date),999999)));
    l_prev_cdc := (l_curr_cdc - p_range);
    p_prev_date := f_get_cdc_date(l_prev_cdc);
    select count(serial_number)
    into p_inst_settled
    from LOTTO_INSTANT_TRACK
    where game_id = l_game_id
    and retailer_num = p_ret_num
    and status = 'Settled'
    and cdc between l_prev_cdc and l_curr_cdc ;
    l_settled_avg := ceil(p_inst_settled / p_range);
    p_expected_stock := ceil(l_settled_avg * p_coefficient);
    select count(serial_number)
    into p_actual_stock
    from LOTTO_INSTANT_track
    where game_id = l_game_id
    and retailer_num = p_ret_num
    and status like 'Confirmed';
    l_forecast_num := ceil((p_expected_stock - p_actual_stock));
    return l_forecast_num;
    exception
    when others then
    dbms_output.put_line(sqlerrm);
    return l_forecast_err;
    end;
    /Now in my function i am passing 1 single value for p_ret_num(retailer number), i value for p_item_id and p-curr_date which is default sysdate.
    now i should be able to pass all retailer number and return those values accordingly.
    I am thinking of having an LOV that will have "ALL" option whereby the user will select and it should return all its corresponding values.
    I know i should be having a loop but don't know how to do that. Can anyone guide me plz.
    Thanks

    not using cursor for performance issues. well from what i've learnt.
    yes, exactly. each and everytime its just replacing the values in the first row itself.
    unhandled exception error
    f_forecast function
    CREATE OR REPLACE function LOTTO_EROUTES.f_forecast(p_ret_num        in varchar2,
                                                        p_item_id        in number,
                                                        p_curr_date      in date,
                                                        p_salesperson    out varchar2,
                                                        p_expected_stock out number,
                                                        p_actual_stock   out number,
                                                        p_inst_settled   out number,
                                                        p_prev_date      out date  ,
                                                        p_range          out number,
                                                        l_settled_avg    out number,
                                                        p_coefficient    out number                                                 
    return number is
    l_forecast_num number;
    l_curr_cdc  varchar2(6);
    l_prev_cdc varchar2(6);
    l_forecast_err varchar2(50) := 0;
    l_game_id number;
    begin
      select game_id,STOCK_COEFF_LEVEL_DAYS,IPS_SETTLED_RANGE_DAYS
      into l_game_id,p_coefficient,p_range
      from items
      where item_id =p_item_id;
    select salesperson
    into p_salesperson
    from lotto_retailers
    where retailer_num = p_ret_num;
    l_curr_cdc  := ltrim(rtrim(to_char(f_get_cdc_num(p_curr_date),999999)));
    l_prev_cdc := (l_curr_cdc - p_range);
    p_prev_date := f_get_cdc_date(l_prev_cdc);
    select count(serial_number)
    into p_inst_settled
    from LOTTO_INSTANT_TRACK
    where game_id = l_game_id
    and retailer_num = p_ret_num
    and status = 'Settled'
    and cdc between l_prev_cdc and l_curr_cdc ;
    l_settled_avg := ceil(p_inst_settled / p_range);
    p_expected_stock := ceil(l_settled_avg * p_coefficient);
    select count(serial_number)
    into p_actual_stock
    from LOTTO_INSTANT_track
    where game_id = l_game_id
    and retailer_num = p_ret_num
    and status like 'Confirmed';
    l_forecast_num := ceil((p_expected_stock - p_actual_stock));
    return l_forecast_num;
    exception
    when others then
    dbms_output.put_line(sqlerrm);
    return l_forecast_err;
    end;
    /calling in my button
    declare
         default_date date := :oe_header.order_date;
    begin
         :oe_lines.order_date_disp := default_date;
    go_block('OE_LINES');
         FOR Get_Ret IN (select retailer_num
                            from lotto_retailers
                            where agent_status_id = 2
                            AND retailer_num = DECODE(:criteria.retailer_num,0,retailer_num,:criteria.retailer_num))
              LOOP
              :OE_LINES.retailer_num := Get_Ret.retailer_num;
              :OE_LINES.FORECAST_CNT := f_forecast(
                      :OE_LINES.retailer_num ,
                                  :criteria.item_id,
                                  :OE_LINES.order_date_disp,
                                  :OE_LINES.salesperson,
                                  :OE_LINES.expected_stock,
                                  :OE_LINES.current_retailer_stock,
                                  :OE_LINES.avg_calculated_amt,
                                  :OE_LINES.from_date,
                                  :OE_LINES.calc_stock_coefficient,
                                  :OE_LINES.avg_daily_sales,
                                  :OE_LINES.stock_coefficient_used
              :OE_LINES.AVG_WEEKLY_SALES := (     :OE_LINES.avg_daily_sales * 7 );
              next_record;
         END LOOP;
    END;

  • Urgent help needed in Rich Text Functionality in BSP (Bold, Italic, etc)

    The standard Appraisal BSP (HAP_DOCUMENT) displays the documents in a plain text box
    Scenario - Standard  BSP application HAP_DOCUMENT for appraisals provides users to input in plain text boxes (htmlb textedit)
                    However, there is requirement to support rich text (bold, italicised, underline etc) for these text boxes. Basically, there are 3 aspects to  this scenario
    1. Enable these plain textboxes with rich text editor
    2. Store the rich text contents of text  boxes in Database table
    3. Convert and display the data stored in db table as rich text.

    Note that the previous reference to tokens only applies if the field is a Multiline text field. Regular fields can't change their font or display based upon mapping data.

  • Help needed to add ecommerce functionality

    i am in the process of creating a website using dreamweaver
    cs3. Almost completed. i have some e books with master reseller
    rights. So i want to sell it through my website. i cannot spend
    initial investment for 3 party sites so i thought of going via
    paypal. but the site instructions aree to complicated.
    1.how do i integrate paypal into my website with shopping
    cart feature?
    2. how do i allow people to download the files only after
    they payed for them?
    3.i have like 20 ebooks which i can sell. So how do i give
    people the option of selecting what they want(adding to cart all
    the individual ebooks they select) and then proceeding to check
    out?
    4.in paypal website they said about something like encryption
    for security.not the ssl but something like to prevent users from
    modifying the code and submitting wrong amount. is it actually
    necessary?

    "coolguythampy" <[email protected]> wrote in
    message
    news:[email protected]...
    >i am in the process of creating a website using
    dreamweaver cs3. Almost
    > completed. i have some e books with master reseller
    rights. So i want to
    > sell
    > it through my website. i cannot spend initial investment
    for 3 party sites
    > so i
    > thought of going via paypal. but the site instructions
    aree to
    > complicated.
    Hm.. if you feel that way, you might want to hire someone to
    do this.
    Setting up a PayPal shopping cart is about the simplest
    method of creating a
    shopping cart site.
    > 1.how do i integrate paypal into my website with
    shopping cart feature?
    This is a large general question which would be answered by
    following the
    instructions on the PayPal site. However, see below re.
    digital downloads.
    > 2. how do i allow people to download the files only
    after they payed for
    > them?
    PayPal doesn't provide for digital downloads. I can
    personally recommend a
    service called Payloadz (www.payloadz.com) which works with
    PayPal and
    delivers your digital items automatically.
    > 3.i have like 20 ebooks which i can sell. So how do i
    give people the
    > option
    > of selecting what they want(adding to cart all the
    individual ebooks they
    > select) and then proceeding to check out?
    I'm not sure how that would work with Payloadz/PayPal, since
    I only sell one
    item. The answer should be on the Payloadz site, or else a
    support ticket to
    them should get you an answer.
    > 4.in paypal website they said about something like
    encryption for
    > security.not
    > the ssl but something like to prevent users from
    modifying the code and
    > submitting wrong amount. is it actually necessary?
    I'm not sure if it's necessary, but you could just be safe
    rather than sorry
    and use the encryption. PayPal support will be able to answer
    a question
    like that.
    Patty Ayers | www.WebDevBiz.com
    Free Articles on the Business of Web Development
    Web Design Contract, Estimate Request Form, Estimate
    Worksheet

  • Need help in generating the ranks

    Hi,
    I need some help in generating the ranks from 1 to 6 for each order_id
    based on the item_cnt
    Order_Id 100 with the Item_cnt 217,112,89,76,55,39 to be ranked from 1 to 6
    Order_Id 200 with the Item_cnt 29,25,22,19,13,13 to be ranked from 1 to 6
    Order_id 300 with the Item_cnt 15,7,6,6,6,4 to be ranked from 1 to 6
    SOURCE DATA TABLE : ORD_TEST
    ORDER_ID ORDER_IN_DATE ORDER_OUT_DATE ITEM_CNT
    100 9/11/2012 9/12/2012 217
    100 9/13/2012 9/15/2012 112
    100 9/14/2012 9/17/2012 89
    100 9/13/2012 9/16/2012 76
    100 9/12/2012 9/15/2012 55
    100 11/9/2012 11/18/2012 39
    100 9/14/2012 9/18/2012 37
    100 9/20/2012 9/22/2012 32
    200 11/9/2012 11/18/2012 29
    200 9/13/2012 9/15/2012 25
    200 9/12/2012 9/15/2012 22
    100 9/12/2012 9/14/2012 22
    100 9/13/2012 9/17/2012 20
    200 9/14/2012 9/17/2012 19
    100 9/14/2012 9/16/2012 19
    100 9/13/2012 9/18/2012 18
    100 9/12/2012 9/19/2012 15
    300 9/11/2012 9/12/2012 15
    200 9/12/2012 9/16/2012 13
    200 9/22/2012 9/29/2012 13
    200 9/13/2012 9/17/2012 12
    200 10/5/2012 10/8/2012 9
    300 9/12/2012 9/18/2012 7
    300 9/12/2012 9/17/2012 6
    300 10/6/2012 10/10/2012 6
    300 4/25/2013 4/27/2013 6
    300 10/6/2012 10/9/2012 4
    300 9/16/2012 9/23/2012 2
    100 10/5/2012 10/8/2012 1
    200 9/11/2012 9/12/2012 1
    QUERY OUTPUT NEEDED IS
    ORDER_ID ORDER_IN_DATE ORDER_OUT_DATE ITEM_CNT RNK
    100 9/11/2012 9/12/2012 217 1
    100 9/13/2012 9/15/2012 112 2
    100 9/14/2012 9/17/2012 89 3
    100 9/13/2012 9/16/2012 76 4
    100 9/12/2012 9/15/2012 55 5
    100 11/9/2012 11/18/2012 39 6
    200 11/9/2012 11/18/2012 29 1
    200 9/13/2012 9/15/2012 25 2
    200 9/12/2012 9/15/2012 22 3
    200 9/14/2012 9/17/2012 19 4
    300 9/11/2012 9/12/2012 15 1
    200 9/12/2012 9/16/2012 13 5
    200 9/22/2012 9/29/2012 13 6
    300 9/12/2012 9/18/2012 7 2
    300 9/12/2012 9/17/2012 6 3
    300 10/6/2012 10/10/2012 6 4
    300 4/25/2013 4/27/2013 6 5
    300 10/6/2012 10/9/2012 4 6
    Below is the script
    CREATE TABLE ORD_TEST (ORDER_ID NUMBER, ORDER_IN_DATE
    DATE,ORDER_OUT_DATE DATE, ITEM_CNT NUMBER)
    INSERT INTO ord_test VALUES
    (100,TO_DATE('9/11/2012','MM/DD/YYYY'),TO_DATE('9/12/2012','MM/DD/YYYY'),217);
    INSERT INTO ord_test VALUES
    (100,TO_DATE('9/13/2012','MM/DD/YYYY'),TO_DATE('9/15/2012','MM/DD/YYYY'),112);
    INSERT INTO ord_test VALUES
    (100,TO_DATE('9/14/2012','MM/DD/YYYY'),TO_DATE('9/17/2012','MM/DD/YYYY'),89);
    INSERT INTO ord_test VALUES
    (100,TO_DATE('9/13/2012','MM/DD/YYYY'),TO_DATE('9/16/2012','MM/DD/YYYY'),76);
    INSERT INTO ord_test VALUES
    (100,TO_DATE('9/12/2012','MM/DD/YYYY'),TO_DATE('9/15/2012','MM/DD/YYYY'),55);
    INSERT INTO ord_test VALUES
    (100,TO_DATE('11/9/2012','MM/DD/YYYY'),TO_DATE('11/18/2012','MM/DD/YYYY'),39);
    INSERT INTO ord_test VALUES
    (100,TO_DATE('9/14/2012','MM/DD/YYYY'),TO_DATE('9/18/2012','MM/DD/YYYY'),37);
    INSERT INTO ord_test VALUES
    (100,TO_DATE('9/20/2012','MM/DD/YYYY'),TO_DATE('9/22/2012','MM/DD/YYYY'),32);
    INSERT INTO ord_test VALUES
    (200,TO_DATE('11/9/2012','MM/DD/YYYY'),TO_DATE('11/18/2012','MM/DD/YYYY'),29);
    INSERT INTO ord_test VALUES
    (200,TO_DATE('9/13/2012','MM/DD/YYYY'),TO_DATE('9/15/2012','MM/DD/YYYY'),25);
    INSERT INTO ord_test VALUES
    (200,TO_DATE('9/12/2012','MM/DD/YYYY'),TO_DATE('9/15/2012','MM/DD/YYYY'),22);
    INSERT INTO ord_test VALUES
    (100,TO_DATE('9/12/2012','MM/DD/YYYY'),TO_DATE('9/14/2012','MM/DD/YYYY'),22);
    INSERT INTO ord_test VALUES
    (100,TO_DATE('9/13/2012','MM/DD/YYYY'),TO_DATE('9/17/2012','MM/DD/YYYY'),20);
    INSERT INTO ord_test VALUES
    (200,TO_DATE('9/14/2012','MM/DD/YYYY'),TO_DATE('9/17/2012','MM/DD/YYYY'),19);
    INSERT INTO ord_test VALUES
    (100,TO_DATE('9/14/2012','MM/DD/YYYY'),TO_DATE('9/16/2012','MM/DD/YYYY'),19);
    INSERT INTO ord_test VALUES
    (100,TO_DATE('9/13/2012','MM/DD/YYYY'),TO_DATE('9/18/2012','MM/DD/YYYY'),18);
    INSERT INTO ord_test VALUES
    (100,TO_DATE('9/12/2012','MM/DD/YYYY'),TO_DATE('9/19/2012','MM/DD/YYYY'),15);
    INSERT INTO ord_test VALUES
    (300,TO_DATE('9/11/2012','MM/DD/YYYY'),TO_DATE('9/12/2012','MM/DD/YYYY'),15);
    INSERT INTO ord_test VALUES
    (200,TO_DATE('9/12/2012','MM/DD/YYYY'),TO_DATE('9/16/2012','MM/DD/YYYY'),13);
    INSERT INTO ord_test VALUES
    (200,TO_DATE('9/22/2012','MM/DD/YYYY'),TO_DATE('9/29/2012','MM/DD/YYYY'),13);
    INSERT INTO ord_test VALUES
    (200,TO_DATE('9/13/2012','MM/DD/YYYY'),TO_DATE('9/17/2012','MM/DD/YYYY'),12);
    INSERT INTO ord_test VALUES
    (200,TO_DATE('10/5/2012','MM/DD/YYYY'),TO_DATE('10/8/2012','MM/DD/YYYY'),9);
    INSERT INTO ord_test VALUES
    (300,TO_DATE('9/12/2012','MM/DD/YYYY'),TO_DATE('9/18/2012','MM/DD/YYYY'),7);
    INSERT INTO ord_test VALUES
    (300,TO_DATE('9/12/2012','MM/DD/YYYY'),TO_DATE('9/17/2012','MM/DD/YYYY'),6);
    INSERT INTO ord_test VALUES
    (300,TO_DATE('10/6/2012','MM/DD/YYYY'),TO_DATE('10/10/2012','MM/DD/YYYY'),6);
    INSERT INTO ord_test VALUES
    (300,TO_DATE('4/25/2013','MM/DD/YYYY'),TO_DATE('4/27/2013','MM/DD/YYYY'),6);
    INSERT INTO ord_test VALUES
    (300,TO_DATE('10/6/2012','MM/DD/YYYY'),TO_DATE('10/9/2012','MM/DD/YYYY'),4);
    INSERT INTO ord_test VALUES
    (300,TO_DATE('9/16/2012','MM/DD/YYYY'),TO_DATE('9/23/2012','MM/DD/YYYY'),2);
    INSERT INTO ord_test VALUES
    (100,TO_DATE('10/5/2012','MM/DD/YYYY'),TO_DATE('10/8/2012','MM/DD/YYYY'),1);
    INSERT INTO ord_test VALUES
    (200,TO_DATE('9/11/2012','MM/DD/YYYY'),TO_DATE('9/12/2012','MM/DD/YYYY'),1);
    select * from ord_test order by item_cnt desc;
    Thank you

    Hi,
    That's called a Top-N Query , and here's one way to do it:
    WITH    got_rnk            AS
         SELECT    o.*
         ,       ROW_NUMBER () OVER ( PARTITION BY  order_id
                                 ORDER BY          item_cnt     DESC
                        )  AS rnk
         FROM      ord_test  o
    SELECT       *
    FROM       got_rnk
    WHERE       rnk     <= 6
    ORDER BY  order_id
    ,            rnk
    ;Analytic functions (such as ROW_NUMBER) are computed after the WHERE clause is applied. If you want tio use the results of an analytic function in a WHERE clause, then you can compute the analytic function in a sub-query (such as got_rnk above), and then use that value in the WHERE clause of a super-query.

  • Help on Dense Rank Function

    Hello All,
    Below is the sql i am trying to execute and the Dense Rank function is giving same result for all of the rows, could you please help me where i am doing wrong
    SELECT
    AMT,
    DENSE_RANK() OVER (PARTITION BY AMT ORDER BY AMT DESC) AS DENSE_RANK
    FROM
    SELECT DISTINCT
    SUM(NVL(TRUNC(NET_AMT) * NVL(GLOBAL1_EXCHANGE_RATE,1),0))
    OVER (PARTITION BY CUSTOMER_BILL_TO_LOC_WID ORDER BY CUSTOMER_BILL_TO_LOC_WID)
    AS AMT
    FROM
    W_SALES_BOOKING_LINE_F
    WHERE
    SALES_ORDER_NUM IN ('10612426','10612450','10612477','32649203')
    AND
    X_MONTH_WID=TO_CHAR(SYSDATE-1,'YYYYMMDD')
    )--ORDER BY AMT DESC Result Set:
    AMT     DENSE_RANK
    0     1
    2,855     1
    6,706     1
    14,265     1

    you have "broken" up your resultset (from the inline view) by AMT (PARTITION BY AMT)
    and per part, you sort this (one row in each partition, not a whole lot of sorting) ( ORDER BY AMT DESC)
    then you assign a ranking based on the sorting action... which yields 1 (DENSE_RANK)
    Are you looking for this
    SELECT
    AMT,
    DENSE_RANK() OVER (ORDER BY AMT DESC) AS DENSE_RANK
    FROM
    SELECT DISTINCT
    SUM(NVL(TRUNC(NET_AMT) * NVL(GLOBAL1_EXCHANGE_RATE,1),0))
    OVER (PARTITION BY CUSTOMER_BILL_TO_LOC_WID ORDER BY CUSTOMER_BILL_TO_LOC_WID)
    AS AMT
    FROM
    W_SALES_BOOKING_LINE_F
    WHERE
    SALES_ORDER_NUM IN ('10612426','10612450','10612477','32649203')
    AND
    X_MONTH_WID=TO_CHAR(SYSDATE-1,'YYYYMMDD')
    )--ORDER BY AMT DESC

Maybe you are looking for

  • ABAP Dump while creating Group Asset

    Hi all I am getting the following dump while creating Group Asset through AS21- Runtime Errors         OBJECTS_OBJREF_NOT_ASSIGNED Except.                CX_SY_REF_IS_INITIAL Date and Time          19.11.2007 21:16:06 Short text      Access via 'NULL

  • My HP officejet 4630 e-All-in-O​ne

    I just bought my printer today and I took everything off, plugged it in and turned it on. And it is in some chinese language. I didn't have the option of putting it in english, and now I dont know how to put it in english. and this is what it looks l

  • Adding text to parentStory destroys XML element / JavaScript, InD CS4

    Dear scripters, I'm currently stuck with this problem: - I'm writing text to text frames on a layout page - while writing some characters/strings are XML tagged (I'm creating an element) - I can do this only once, because adding more text after I hav

  • Extract Stopped for the Device

    hi guys how do I configure the Doe for stop this message ? Extract Stopped for the Device. Days not synced exceeds configured thresholdEnable Extract I found these configurations. Configure Maximum Level Values to Stop Extract for Receivers Maximum T

  • Preloader not working when published

    Hi...I have situation with my preloader. I am loading audio from an external folder. When I click on the audio a preloader loads the audio and upon completion plays audio. My problem lies in that when I test the movie everything works as expected. On