Need help in some what complex transpose of data...

Dear Team,
I need a small help, to transpose the data...
The Input data is shown below...
Product
Level
Position
Route
1st_Prod_id
Request_Flag
Qty
99904228
LEVEL_1
1
1
828452
Y
0
96500436
LEVEL_2
2
1
828452
N
1
96500437
LEVEL_2
3
1
828452
N
1
96500437
LEVEL_3
4
1
828452
N
2
66500084
LEVEL_3
5
1
828452
Y
0
67653972
LEVEL_3
6
1
828452
N
2
47418545
LEVEL_4
7
1
828452
Y
0
47418545
LEVEL_5
8
1
828452
N
0
35264043
LEVEL_5
9
1
828452
N
2
37411616
LEVEL_5
10
1
828452
N
0
35264044
LEVEL_6
11
1
828452
Y
2
The output format is shown below along with transpose logic...
Dmd_Product
From_Prod
From_Level
To_Prod
To_Level
Total_QtY
99904228
99904228
LEVEL_1
66500084
LEVEL_3
4
99904228
66500084
LEVEL_3
47418545
LEVEL_4
2
99904228
47418545
LEVEL_4
35264044
LEVEL_6
4
1. Depending upon the Req_Flag = 'Y', we have to identify our from_product - to_product, & from_level - to_level...
2. Between from_product - to_product we have to sum up the quantity (QTY)
3. The position 1 product should remain as it throught out the transformation and shown under new column Dmd_Prod
4. Between Position 1 and Position 5 we have 2 Req_Flag --> One req_flag = 'Y' at pos = 1 and another req_flag = 'Y' at pos = 5
   So my From_Product will be product as pos = 1 and to_product will be product at pos = 5...
5. The same iteration goes on and my product at pos = 5 becomes my from_product and another item at pos = 7 becomes to_product... and so on...
I hope i am clear in my explanation...
please give me some hints or tips how to solve it...
Attached is the create table statement for sample data...
Create Table test As
(Select 99904228 prod, 'LEVEL_1' l_level, 828452 first_prod_id,  1 position,  1 route, 'Y' req_flag, 0 qty From dual Union All 
Select 96500436 prod, 'LEVEL_2' l_level, 828452 first_prod_id,  2 position,  1 route, 'N' req_flag, 1 qty From dual Union All
Select 96500437 prod, 'LEVEL_2' l_level, 828452 first_prod_id,  3 position,  1 route, 'N' req_flag, 1 qty From dual Union All
Select 96500437 prod, 'LEVEL_3' l_level, 828452 first_prod_id,  4 position,  1 route, 'N' req_flag, 2 qty From dual Union All
Select 66500084 prod, 'LEVEL_3' l_level, 828452 first_prod_id,  5 position,  1 route, 'Y' req_flag, 0 qty From dual Union All
Select 67653972 prod, 'LEVEL_3' l_level, 828452 first_prod_id,  6 position,  1 route, 'N' req_flag, 2 qty From dual Union All
Select 47418545 prod, 'LEVEL_4' l_level, 828452 first_prod_id,  7 position,  1 route, 'Y' req_flag, 0 qty From dual Union All
Select 47418545 prod, 'LEVEL_5' l_level, 828452 first_prod_id,  8 position,  1 route, 'N' req_flag, 0 qty From dual Union All
Select 35264043 prod, 'LEVEL_5' l_level, 828452 first_prod_id,  9 position,  1 route, 'N' req_flag, 2 qty From dual Union All
Select 37411616 prod, 'LEVEL_5' l_level, 828452 first_prod_id,  10 position, 1 route, 'N' req_flag, 0 qty From dual Union All
Select 35264044 prod, 'LEVEL_6' l_level, 828452 first_prod_id,  11 position, 1 route, 'Y' req_flag, 2 qty From dual
Regards
nic..

Maybe
select dmd_product,
       from_product,
       from_level,
       to_product,
       to_level,
       total_qty,
       agg_yield
  from (select position,
               dmd_product,
               case when to_flag = 'Y' and lag(from_flag,1) over (order by position) = 'Y'
                    then lag(from_product,1) over (order by position)
               end from_product,
               case when to_flag = 'Y' and lag(from_flag,1) over (order by position) = 'Y'
                    then lag(from_level,1) over (order by position)
               end from_level,
               to_product,
               to_level,
               total_qty,
               case when total_qty is not null
                    then yield
               end agg_yield
          from (select position,
                      first_value(dmd_product ignore nulls) over (order by position) dmd_product,
                      from_product,
                      from_level,
                      to_product,
                      to_level,
                      case to_flag when 'Y'
                                   then total_qty -
                                        lag(total_qty,1) over (order by position) +
                                        lead(qty,1) over (order by position)
                      end total_qty,
                      case when to_flag = 'Y'
                            and lead(to_flag,1) over (order by position) = 'N'
                           then yield
                           else yield * lead(yield,1) over (order by position) / 100
                      end yield,
                      from_flag,
                      to_flag
                 from (select position,
                              case when req_flag = 'Y'
                                    and position = (select min(position)
                                                      from test
                                                     where req_flag = 'Y'
                                   then prod
                              end dmd_product,
                              prod from_product,
                              l_level from_level,
                              req_flag from_flag,
                              lead(prod,1) over (order by position) to_product,
                              lead(l_level,1) over (order by position) to_level,
                              lead(req_flag,1) over (order by position) to_flag,
                              qty,
                              sum(qty) over (order by position) total_qty,
                              last_value(nullif(yield,100) ignore nulls) over (order by position) yield
                         from test
                where from_flag != 'N'
                   or to_flag != 'N'
         where dmd_product is not null
where from_product is not null
order by position
DMD_PRODUCT
FROM_PRODUCT
FROM_LEVEL
TO_PRODUCT
TO_LEVEL
TOTAL_QTY
AGG_YIELD
99904228
99904228
LEVEL_1
66500084
LEVEL_3
4
92
99904228
66500084
LEVEL_3
47418545
LEVEL_4
2
90
99904228
47418545
LEVEL_4
35264044
LEVEL_6
4
97.02
Regards
Etbin

Similar Messages

  • Hi! My notebook had to be fixed and I lost everything. I´ve downloaded iTunes and, of course, it´s empty. What happens if I sync my Ipod nano? Will I loose all music that is in my ipod? Need help, please! What should I do to keep my music?

    Hi!
    My notebook had to be fixed and I´ve lost everything. I´ve downloaded iTunes and, of course, it´s empty. What happens if Isync my Ipod Nano? Will I loose all music that is in my Ipod? Need help, please! What should I do to keep my music? What should I do to transfer the music in the Ipod to itunes?
    Thanks!!!

    How to use your iPod to move your music to a new computer

  • My ipod touch is in DFU mode 5g I need help, do not want to lose my data, please help in Spanish

    I need help, do not want to lose my data, PLEASE HELP IN SPANISH

    Una vez que el dispositivo está pidiendo ser restaurado con iTunes ... ya es demasiado tarde para salvar nada ... y usted debe continuar con la recuperación de ...
    Vea aquí> http://support.apple.com/kb/HT1808
    Es posible que tenga que probar más de una vez ... Asegúrese de seguir todos los pasos ...
    Tómese su tiempo ... Preste especial atención a los pasos 3 y 4.
    Para minimizar la pérdida ...
    Después de haber recuperado su dispositivo ...
    Re-sincronizar su contenido o restauración de la última copia de seguridad ...
    Restaurar desde copia de seguridad> http://support.apple.com/kb/ht1766
    Once the Device is asking to be Restored with iTunes... it is too late to save anything... and you must continue with the Recovery...
    See Here  >  http://support.apple.com/kb/HT1808
    You may need to try this More than Once...  Be sure to Follow ALL the Steps...
    Take your time... Pay particular attention to Steps 3 and 4.
    To minimise loss...
    After you have Recovered your Device...
    Re-Sync your Content or Restore from the most recent Backup...
    Restore from Backup  >  http://support.apple.com/kb/ht1766

  • I need Help with Some CSS

    I am in the process of making a new template for my site.
    I can't really provide any code and here's why, I need help finding the code that I need to change. The new template is actually being designed here.
    If you scroll over the home link you will find a sub-menu pops up, if you scroll over the menu items they get bigger and come 'at" you, if you hover over sub-2 and then hover over sub-3 you will notice there is a wild transition effect, I need to know how to get rid of those, it is a different CSS code from another template link to my site. I can't find out how, if somebody could please help me out it would be wonderful. Thank you a whole bunch in advance.

    Your menu moves for a couple of reasons first, you have a border in the hover, which is going to move all of the text.  You can get rid of the border in the hover or add a border of the same size/style in the active.
    The second reason it appears you have some paddng in the hover that moves the text.
    Find those and you can solve the issue.
    Gary

  • I need help getting some photos off a really old ipod

    Ok so here it is.... My grandparents way back when gave me an ipod video, I just recently found it and realized it has photo's on it that I would like to keep. My problems are 1. I don't have the original computer I used for it 2. when I plug it in my computer thinks it's a hard drive 3. autoplay won't give me the option to import the photo's to my computer and 4. itunes doesn't seem to have an option to transfer photo's from ipods to your pictures folder.... if any one could help I'd appriciate it.

    The photos you synced to your iPod through iTunes are no longer in their full resolution, but instead are scaled down thumbnails of those photos.  So if you do manage to get them off your iPod, they will be quite small in size compared to the original ones you lost.
    In order to get them off of your iPod, you'll need the help of some sort of 3rd party software. Here is one option.  You can Google for more.
    http://www.macroplant.com/podtopc/
    B-rock

  • Need help with some Coldfusion data structures

    Hello,
    I need to keep some sort of a list that contains a page, and then that page will have associated with it values.  So,
    if I have page 1, I may have values 240, 245, 300.  Then, on to page 2, and I will have say, 344, 29, etc.
    So, what I will have is something that "could maybe" be a 2 dimensional array where one of the elements is a list?
    Or, do I set up a struct say, page.number and page.value list, and put that struct in an array?
    Plus, the fun part is I have to save this bad boy in session.  I've been looking around the web for some examples, no
    luck.  So, to reiterate:
    I have a page number that has to be associated with a list.  That entire structure needs to be in an array or list of
    some sort, and stored in session.
    Thanks in advance!

    Really Google did not show anything like:
    <cfset session.pageAry = [
         {page="pageOne", numList="240,245,300"},
         {page="pageTwo", numList="344,29"}]>
    <cfdump var="#session.pageAry#">
    OR
    <cfset session.pageAry = arrayNew(1)>
    <cfset arrayAppend(session.pageAry, strutNew())>
    <cfset session.pageAry[1].page = "pageOne">
    <cfset session.pageAry[1].numList = "240,245,300">
    <cfset arrayAppend(session.pageAry, strutNew())>
    <cfset session.pageAry[2].page = "pageTwo">
    <cfset session.pageAry[2].numList = "344,29">
    OR
    The <cfscript> version of these examples.

  • I need help in some programs

    i'm new in a jave and i need to write some programs
    1) write a program that allows the user to enter a range of number. for that range of number, list the numbers and state their properties:
    prime or not rrime; deficient, perfect, or abundant; smith number or not.
    2) write a program that finds the largest Smith number possible that can be held in Java integer

    BigDaddyLoveHandles wrote:
    Psyber wrote:
    Here's the algorithm for perfect numbers:
    boolean p_num(int number) {
    int sum = 1;
    for (int n = 2; n <= number / 2; n++)
    if (number % n == 0)
    sum += n;
    return sum == number ? true : false;
    }Now hand over the dukes.Why not:
    return sum == number;
    Whaddya expect for 10 dukes?

  • Need help on some actionscript

    i have a few problems with the flash menubar. I am trying to
    make the movie goto a certain frame when a sub menu is click, But i
    dont know where to start. can anyone help?
    Jak - Cheers if you can help
    iv got what iv done so far:
    http://users.cjb.net/nowherefast/menu.swf
    If it will help iv got the code below:
    stop();
    import mx.controls.Menu;
    import mx.controls.MenuBar;
    var my_mb:MenuBar;
    var my_menu:Menu = my_mb.addMenu("Menu");
    my_menu.addMenuItem({label:"File", instanceName:"File"});
    my_menu.addMenuItem({label:"Open", instanceName:"Open"});
    my_menu.addMenuItem({label:"Settings",
    instanceName:"Settings"});
    //Create listener object.
    var mbListenerbject = new Object();
    mbListener.change = function(evt_objbject) {
    var menuItem_objbject = evt_obj.menuItem;
    switch (menuItem_obj.attributes.instanceName) {
    case "About":
    trace("Open menu item");
    break;
    case "Services":
    trace("Open menu item");
    break;
    case "Settings":
    trace("Close menu item");
    break;
    trace(menuItem_obj);
    //Add listener.
    my_menu.addEventListener("change", mbListener);

    i have a few problems with the flash menubar. I am trying to
    make the movie goto a certain frame when a sub menu is click, But i
    dont know where to start. can anyone help?
    Jak - Cheers if you can help
    iv got what iv done so far:
    http://users.cjb.net/nowherefast/menu.swf
    If it will help iv got the code below:
    stop();
    import mx.controls.Menu;
    import mx.controls.MenuBar;
    var my_mb:MenuBar;
    var my_menu:Menu = my_mb.addMenu("Menu");
    my_menu.addMenuItem({label:"File", instanceName:"File"});
    my_menu.addMenuItem({label:"Open", instanceName:"Open"});
    my_menu.addMenuItem({label:"Settings",
    instanceName:"Settings"});
    //Create listener object.
    var mbListenerbject = new Object();
    mbListener.change = function(evt_objbject) {
    var menuItem_objbject = evt_obj.menuItem;
    switch (menuItem_obj.attributes.instanceName) {
    case "About":
    trace("Open menu item");
    break;
    case "Services":
    trace("Open menu item");
    break;
    case "Settings":
    trace("Close menu item");
    break;
    trace(menuItem_obj);
    //Add listener.
    my_menu.addEventListener("change", mbListener);

  • Need help with some JS installing Bumpbox 2.0

    I am trying to add a lightbox effect to a pdf on my website, I found a Javascript plugin at http://www.artviper.net/bumpbox-demo/index.html that looks like it should do the trick, but I am having trouble getting it to work.
    To narrow down the problem I created a test.html file that I stuck in the root directory of the folder I downloaded from their site (so I am working locally off my desktop at this point)
    My code is as follows... I feel like I am missing something super obvious, does anyone see it? (do I need to define the .bump class in the css file?)
    Thank you in advance for the much needed help!
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    </head>
    <body>
          <a href="http://www.artviper.net/test.pdf" class="bump" rel="800-350">PDF File &raquo;</a><br />
    <script type="text/javascript" src="js/mootools.js"></script>
    <script type="text/javascript" src="js/bumpbox-2.0.1.js"></script>
    <script type="text/javascript"> doBump( '.bump',750, 500, '111', '900', '0.8', 5, 1 ,'333', 15,'000', 4,
                     Fx.Transitions.Bounce.EaseOut,
                     Fx.Transitions.Bounce.EaseOut,
                     'images/demo_bg_bumpbox.png',
                     'top left',
                     'repeat-x' ); </script>
    </body>
    </html>

    These paths won't work because they point to files on your local hard drive.
    <script type="text/javascript" src="file:///Macintosh HD/Users/Robert/Downloads/bumpbox Folder copy/js/mootools.js"></script>
    <script type="text/javascript" src="file:///Macintosh HD/Users/Robert/Downloads/bumpbox Folder copy/js/bumpbox-2.0.1.js"></script>
    Are you working within a properly defined local site?
    Did you save those javascript files to the js folder in your local site root?
    Correct path to scripts for this test page should look like this:
    <script type="text/javascript" src="../js/mootools.js"></script>
    <script type="text/javascript" src="../js/bumpbox-2.0.1.js"></script>
    PS.  Do not add spaces to folder or file names.  It can create problems for web files.
    Nancy O.

  • I need help with some character replacement

    I have a package that calls another package to determine if there are any of 4 values (&,<,>,") and I want to replace the value in the package with the proper value for HTML. If I can get the & figured out I can handle the rest, I just need help getting past this part. I consider myself a novice at PL/SQL so any input is welcome. The package body gives me this message on compile:
    PLS-00103: Encountered the symbol ";" when expecting one of the following:
    if
    I'm stuck on how to do the actual replace within the package. The code for the replace block is below: using a package and procedure in the package body. I'm using TOAD 9.x on 10gR2.
    I have a feeling the the assignment of the := is having a problem but I'm not sure. This is all part of a larger chunk of code I've written to dynamically create audit triggers (before and after) for my data tables and it writes out to the audit in xml on a row by row basis. The XML insert is failing on on the 4 special characters that need to be converted to their HTML proper use.
    CREATE OR REPLACE package pkg_audit_xml
    as
    procedure change_illegal_char
    (p_new_val in varchar2,
    p_old_val in varchar2,
    p_has_changed in out boolean);
    end;                    
    CREATE OR REPLACE package body pkg_audit_xml
    as
    procedure change_illegal_char
    (p_new_val in varchar2,
    p_old_val in varchar2,
    p_has_changed in out boolean)
    is
    v_temp clob;
    begin
    if ( nvl(p_new_val, ' ') <> nvl(p_old_val, ' ') ) then
    p_has_changed := true;
    p_old_val := replace(p_old_val,'&','&amp;');
    p_new_val := replace(p_new_val,'&','&amp;');
    end if;
    end;
    end pkg_audit_xml;
    /

    SQL> create or replace procedure aa_test(a_old_val IN varchar2) as
      2  begin
      3   a_old_val := substr(a_old_val,1,4);
      4   dbms_output.put_line(a_old_val);
      5  end;
      6  /
    Warning: Procedure created with compilation errors.
    SQL> show errors
    Errors for PROCEDURE AA_TEST:
    LINE/COL ERROR
    3/2      PL/SQL: Statement ignored
    3/2      PLS-00363: expression 'A_OLD_VAL' cannot be used as an assignment
             target

  • HT5538 I dont really get this i need help setting some things up on my Ipod.Can you help?

    I need help setting up my Imessage and FaceTime.I have tryed and its not working.

    iOS: Using FaceTime
    iOS: About Messages
    iOS: Troubleshooting FaceTime and iMessage activation
    iOS: Troubleshooting Messages
    iOS: Troubleshooting FaceTime

  • Need help with Importing These Kinds of Excel Data Sheets

    hy there, Can someone Assist me with this.
    I got a package in SSIS. where I need to import Excel data sheets.
    Those sheets are coming from Cube.
    And So their format is bit different
    Kindly help me how to import those With DATA FLOW TASK.
    And ,
    As you can see Excel sheets got Filter on their Columns.
    So I am Getting much often Errors in importing those sheets Via DATA FLOW TASK.
    Thanks In Advance.
    # Note.
    I can not Edit each Excel File Before running packages.
    Packages are automated.
    And also the sheets are automated, they get store in the FTP on a cyclic job.
    So Have to Do it on PAckage level

    You cannot hit a moving target, your data quality is at risk, too. Even if a package succeeded there is still a degree of suspect whether the data ended in the right place.
    You can create a helper program that checks for data integrity, e.g. a series of SQL queries can be executed against the source to pinpoint what metadata shape the Excel arrived in. Then branch the package flow based on one or the other variant (there will
    be only a handful). The branching can be done by using Precedence Constraints. Hey, but see what I say about above.
    Arthur My Blog
    Okay than I must do it differently. OR get the source in a better and secured manner.

  • I'm new to flash and need help with some controls

    I'm builidng a site that has a portfiolio of work to display.
    When the visitor arrives at the portfolio page he (or she) is
    faced with a split panel. The right panel displays a summary of a
    client and the work. The left panel displays the work examples
    attributed to that client. By clicking forward and backward arrows
    in the right panel, the visitor can call the summaries of the
    different clients. Landing on a client page 'opens' a separate swf,
    called using loader component, that contains the portfolio of that
    client's work into the left panel
    1. I want forward and backward arrows located on the main
    movie in the left panel to control the progress of the loaded swf,
    rather than using forward and backward arrows on the loaded swf.
    2. I want to prevent the forward and backward arrows in both
    panels from clicking beyond frames in the Portfolio area of the
    timeline.
    3. I want the backward arrow to be innactive on the first
    frame, and the forward arrow to be innactive on the last frame.
    I have no problems making the arrows work on the main movie
    controlling the client summaries. What I don't know how to do is
    make them control the movement of the loaded swf, or #2 and #3.
    Any help will be greatefully appreciated. Thanks in advance,
    Art

    "Art Lazaar" <[email protected]> wrote in
    message news:[email protected]...
    > Tralfaz,
    >
    > Thanks for your response. I must be missing something
    very simple here, but I
    > can't make this work no matter what I do. Let me see if
    I understand some of it:
    >
    > On my main movie I put the fwd_btn and rew_butn
    codes...do I put these on the
    > actual buttons, or in an actions time line? When I put
    them on the buttons, I
    > get an error report saying they need to be in an 'on'
    event handler. I thought
    > that's what 'onRelease' was.
    >
    > On my loaded movie, I place the 'one.swf' code. I'm not
    sure what you mean by
    > placing the code inside a loop, I don't seem to be able
    to find a reference to
    > using 'loop' anywhere. When I use an 'onEnterFrame', I
    presume I do that with
    > onEventClip(enterFrame). When I do that, if I run the
    'one.swf' by itself, i
    > get an error report saying onEeventClip is for movies
    only. But there's no
    > error report when it loads from the main movie. What
    happens tho' is it loops
    > continuously, even if there are stops() in it.
    >
    > Boy, am I confused ;)
    >
    > I am really baffled by this seemingly simple little
    task. Your help is
    > gratefully appreciated.
    >
    > Art
    >
    >
    >
    Hi Art,
    There are different coding methods, depending on where you
    put code..
    1) Frame code
    Click on a frame of the timeline to enter frame code
    2) Attached code for movieclips and buttons
    Click once on a movieclip or a button then enter attached
    code
    To make an onEnterFrame event for a movieclip, first chose
    either frame code or attached code method. I personally rarely ever
    use
    attached code because it hides code in places that can be
    hard to find. Almost all my coding is frame code, but it's a
    personal
    choice.
    Frame code method to make an onEnterFrame for the main
    timeline..
    // put this code into a frame on the main timeline
    this.onEnterFrame = function()
    // do something once per frame at the frame rate
    checkMyButtons(); // once per frame we will check on the
    button status
    OR
    Attached Code method to attach an onEnterFrame event to a
    movieclip
    // click once on the movieclip (don't dbl click it .. stay at
    the root timeline level)
    onClipEvent(enterFrame)
    // do something once per frame at the frame rate
    Those two types of code are not interchangeable. One type
    must be entered into a frame and the other style must be attached
    to a
    movieclip or you will get errors.
    Then there is the DOT syntax way to write frame code that is
    equivalent to attaching code..
    myMovieClip.onRelease = function()
    trace("release");
    myMovieClip.onPress = function()
    trace("press");
    myMovieClip.onDragOut = function()
    trace("drag out");
    tralfaz

  • Need help on derivation of complex column

    Hi,
    I have a requirement to derive a column in my report which has slightly complex logic and hence need your help.
    I have oracle 10g database.
    Background: The data is stored in a quiet complex way in table hence trying to let you understand in words. I have incidences stored in my table. These incidences can be completed by certain numbers of plans and further a single plan can be completed by certain numbers of activities. Structure is like below.
    Table 1
    *Incidences*            *Incidence_id*
    Incidence_1                     1
    Incidence_2                     2
    Incidence_3                     3
    Table 2
    *Plan_name*        *Plan_id*     *incidence_id*
    Plan_1                       1             1
    Plan_2                       2             1
    Plan_3                       3             1
    Plan_1                       1             2
    Plan_2                       2             2
    Plan_3                       3             2
    Plan_1                       1             3
    Plan_2                       2             3
    Plan_3                       3             3
    I have Activity 1, Activity 2, Activity 3, Activity 4 are predefined activities which can be repeated in a plan like shown in below table.
    Table 3
    *Activity _name*      *Activity_id*        *Plan_id*           *incidence_id*
    Activity_1                      1                      1                     1
    Activity_2                      2                      1                     1
    Activity_3                      3                      1                     1
    Activity_4                      4                      1                     1
    Activity_1                      5                      1                     1
    Activity_1                      6                      2                     1
    Activity_2                      7                      2                     1
    Activity_3                     8                       3                     1
    Activity_2                     9                       3                     1
    Activity_1                    10                      3                     1Now in table 3 for plan_id 1 I have two Activity 1 and one Activity 3. from my functional knowledge I know that first Activity 1 is the parent activity of Activity 3, but there is no any way in a table to identify that logically. Can you please tell me any way so that I can have first Activity 1 as my output if I want parent activity of Activity 3?
    Let me know if you have any questions to understand my requirement.
    Edited by: 968625 on Jan 14, 2013 7:08 AM
    Edited by: 968625 on Jan 14, 2013 7:37 AM

    Hi,
    968625 wrote:
    Hi,
    I have a requirement to derive a column in my report which has slightly complex logic and hence need your help.
    I have oracle 10g database.
    Background: The data is stored in a quiet complex way in table hence trying to let you understand in words. I have incidences stored in my table. These incidences can be completed by certain numbers of plans and further a single plan can be completed by certain numbers of activities. Structure is like below.
    Table 1
    *Incidences*            *Incidence_id*
    Incidence_1                     1 ...
    Whenever you have a question, please post CREATE TABLE and INSERT statements for your sample data, so the poeple who want to help you can re-create the problem and test their ideas. Also post the results you want from that data.
    See the forum FAQ {message:id=9360002}
    Now in table 3 for plan_id 1 I have two Activity 1 and one Activity 3. from my functional knowledge I know that first Activity 1 is the parent activity of Activity 3, but there is no any way in a table to identify that logically. Can you please tell me any way so that I can have first Activity 1 as my output if I want parent activity of Activity 3?If you want a query to know (or deduce) that Activity 1 is the parent of Activity 3, then that information has to be stored someplace where the query can see it.
    If each activity can have (at most) 1 parent, then it seems like the most logical place is the table3: add another column to the table, and keep the parent activity there.
    If a single parent can have multiple children, and, at the same time, a single child can have multiple parents, then you probably need a separate table for the parent-child relationships.
    You could hard-code information about the parent-child relationships in the query itself, but I doubt that's the best way to solve this problem.
    Let me know if you have any questions to understand my requirement.I don't understand what results you want from the given data. Once again, please post CREATE TABLE and INSERT statements for the sample data, and the exact results you want. Use specific examples from that output to explain how you get the right results from the given data.

  • [8i] Need help with some workday calculations

    At the beginning of the month, I got help with a workday calculation in: [8i] Help with function with parameters (for workday calculation)
    Now, as it turns out, I was able to locate a function in the database that does what I want, however, it is much slower to use the function than to join two copies of the CALN table (Please see referenced thread for details. I can copy them to this thread if necessary.) I need to verify that the pre-existing function has 'DETERMINISTIC' in it, as I would guess that if it doesn't, it would be much slower than it could be.
    But now, I've come across a situation where I have to do multiple workday calculations in the same query--enough that I have to join 6 copies of my CALN table. I can't imagine that is at all efficient. I believe it was Frank K. who said (in the original thread) that if the function was slow, I should consider alternatives. Can anyone help me identify some of those alternatives? I'm definitely at that point now. (This query is one I'm using as the base for a report in Oracle BI, and let's just say it doesn't like my query, even though my syntax appears to be correct, and I would guess that joining 6 copies of one table is at least partly to blame for this).
    Note: I'm working with Oracle 8i

    OK, I finally have some sample data... I tried to make it thorough. I've included data in the CALN table YTD + tomorrow, so that any workday calculations using SYSDATE will work.
    CREATE TABLE caln
    (     clndr_dt     DATE          NOT NULL
    ,     clndr_yr     NUMBER
    ,     shop_day     NUMBER
    ,     shop_dt          DATE
    ,     shop_wk          NUMBER
    ,     shop_yr          NUMBER
    ,     shop_days     NUMBER
    ,     clndr_days     NUMBER
         CONSTRAINT caln_pk PRIMARY KEY (clndr_dt)
    INSERT INTO     caln
    VALUES (To_Date('12/23/2009','mm/dd/yyyy'),2009,247,To_Date('12/23/2009','mm/dd/yyyy'),51,2009,7631,10950);
    INSERT INTO     caln
    VALUES (To_Date('01/01/2010','mm/dd/yyyy'),2010,0,To_Date('12/23/2009','mm/dd/yyyy'),52,2009,7631,10959);
    INSERT INTO     caln
    VALUES (To_Date('01/02/2010','mm/dd/yyyy'),2010,0,To_Date('12/23/2009','mm/dd/yyyy'),52,2009,7631,10960);
    INSERT INTO     caln
    VALUES (To_Date('01/03/2010','mm/dd/yyyy'),2010,0,To_Date('12/23/2009','mm/dd/yyyy'),1,2010,7631,10961);
    INSERT INTO     caln
    VALUES (To_Date('01/04/2010','mm/dd/yyyy'),2010,1,To_Date('01/04/2010','mm/dd/yyyy'),1,2010,7632,10962);
    INSERT INTO     caln
    VALUES (To_Date('01/05/2010','mm/dd/yyyy'),2010,2,To_Date('01/05/2010','mm/dd/yyyy'),1,2010,7633,10963);
    INSERT INTO     caln
    VALUES (To_Date('01/06/2010','mm/dd/yyyy'),2010,3,To_Date('01/06/2010','mm/dd/yyyy'),1,2010,7634,10964);
    INSERT INTO     caln
    VALUES (To_Date('01/07/2010','mm/dd/yyyy'),2010,4,To_Date('01/07/2010','mm/dd/yyyy'),1,2010,7635,10965);
    INSERT INTO     caln
    VALUES (To_Date('01/08/2010','mm/dd/yyyy'),2010,5,To_Date('01/08/2010','mm/dd/yyyy'),1,2010,7636,10966);
    INSERT INTO     caln
    VALUES (To_Date('01/09/2010','mm/dd/yyyy'),2010,0,To_Date('01/08/2010','mm/dd/yyyy'),1,2010,7636,10967);
    INSERT INTO     caln
    VALUES (To_Date('01/10/2010','mm/dd/yyyy'),2010,0,To_Date('01/08/2010','mm/dd/yyyy'),2,2010,7636,10968);
    INSERT INTO     caln
    VALUES (To_Date('01/11/2010','mm/dd/yyyy'),2010,6,To_Date('01/11/2010','mm/dd/yyyy'),2,2010,7637,10969);
    INSERT INTO     caln
    VALUES (To_Date('01/12/2010','mm/dd/yyyy'),2010,7,To_Date('01/12/2010','mm/dd/yyyy'),2,2010,7638,10970);
    INSERT INTO     caln
    VALUES (To_Date('01/13/2010','mm/dd/yyyy'),2010,8,To_Date('01/13/2010','mm/dd/yyyy'),2,2010,7639,10971);
    INSERT INTO     caln
    VALUES (To_Date('01/14/2010','mm/dd/yyyy'),2010,9,To_Date('01/14/2010','mm/dd/yyyy'),2,2010,7640,10972);
    INSERT INTO     caln
    VALUES (To_Date('01/15/2010','mm/dd/yyyy'),2010,10,To_Date('01/15/2010','mm/dd/yyyy'),2,2010,7641,10973);
    INSERT INTO     caln
    VALUES (To_Date('01/16/2010','mm/dd/yyyy'),2010,0,To_Date('01/15/2010','mm/dd/yyyy'),2,2010,7641,10974);
    INSERT INTO     caln
    VALUES (To_Date('01/17/2010','mm/dd/yyyy'),2010,0,To_Date('01/15/2010','mm/dd/yyyy'),3,2010,7641,10975);
    INSERT INTO     caln
    VALUES (To_Date('01/18/2010','mm/dd/yyyy'),2010,11,To_Date('01/18/2010','mm/dd/yyyy'),3,2010,7642,10976);
    INSERT INTO     caln
    VALUES (To_Date('01/19/2010','mm/dd/yyyy'),2010,12,To_Date('01/19/2010','mm/dd/yyyy'),3,2010,7643,10977);
    INSERT INTO     caln
    VALUES (To_Date('01/20/2010','mm/dd/yyyy'),2010,13,To_Date('01/20/2010','mm/dd/yyyy'),3,2010,7644,10978);
    INSERT INTO     caln
    VALUES (To_Date('01/21/2010','mm/dd/yyyy'),2010,14,To_Date('01/21/2010','mm/dd/yyyy'),3,2010,7645,10979);
    INSERT INTO     caln
    VALUES (To_Date('01/22/2010','mm/dd/yyyy'),2010,15,To_Date('01/22/2010','mm/dd/yyyy'),3,2010,7646,10980);
    INSERT INTO     caln
    VALUES (To_Date('01/23/2010','mm/dd/yyyy'),2010,0,To_Date('01/22/2010','mm/dd/yyyy'),3,2010,7646,10981);
    INSERT INTO     caln
    VALUES (To_Date('01/24/2010','mm/dd/yyyy'),2010,0,To_Date('01/22/2010','mm/dd/yyyy'),4,2010,7646,10982);
    INSERT INTO     caln
    VALUES (To_Date('01/25/2010','mm/dd/yyyy'),2010,16,To_Date('01/25/2010','mm/dd/yyyy'),4,2010,7647,10983);
    INSERT INTO     caln
    VALUES (To_Date('01/26/2010','mm/dd/yyyy'),2010,17,To_Date('01/26/2010','mm/dd/yyyy'),4,2010,7648,10984);
    INSERT INTO     caln
    VALUES (To_Date('01/27/2010','mm/dd/yyyy'),2010,18,To_Date('01/27/2010','mm/dd/yyyy'),4,2010,7649,10985);
    INSERT INTO     caln
    VALUES (To_Date('01/28/2010','mm/dd/yyyy'),2010,19,To_Date('01/28/2010','mm/dd/yyyy'),4,2010,7650,10986);
    INSERT INTO     caln
    VALUES (To_Date('01/29/2010','mm/dd/yyyy'),2010,20,To_Date('01/29/2010','mm/dd/yyyy'),4,2010,7651,10987);
    INSERT INTO     caln
    VALUES (To_Date('01/30/2010','mm/dd/yyyy'),2010,0,To_Date('01/29/2010','mm/dd/yyyy'),4,2010,7651,10988);
    INSERT INTO     caln
    VALUES (To_Date('01/31/2010','mm/dd/yyyy'),2010,0,To_Date('01/29/2010','mm/dd/yyyy'),5,2010,7651,10989);
    INSERT INTO     caln
    VALUES (To_Date('02/01/2010','mm/dd/yyyy'),2010,21,To_Date('02/01/2010','mm/dd/yyyy'),5,2010,7652,10990);
    INSERT INTO     caln
    VALUES (To_Date('02/02/2010','mm/dd/yyyy'),2010,22,To_Date('02/02/2010','mm/dd/yyyy'),5,2010,7653,10991);
    INSERT INTO     caln
    VALUES (To_Date('02/03/2010','mm/dd/yyyy'),2010,23,To_Date('02/03/2010','mm/dd/yyyy'),5,2010,7654,10992);
    INSERT INTO     caln
    VALUES (To_Date('02/04/2010','mm/dd/yyyy'),2010,24,To_Date('02/04/2010','mm/dd/yyyy'),5,2010,7655,10993);
    INSERT INTO     caln
    VALUES (To_Date('02/05/2010','mm/dd/yyyy'),2010,25,To_Date('02/05/2010','mm/dd/yyyy'),5,2010,7656,10994);
    INSERT INTO     caln
    VALUES (To_Date('02/06/2010','mm/dd/yyyy'),2010,0,To_Date('02/05/2010','mm/dd/yyyy'),5,2010,7656,10995);
    INSERT INTO     caln
    VALUES (To_Date('02/07/2010','mm/dd/yyyy'),2010,0,To_Date('02/05/2010','mm/dd/yyyy'),6,2010,7656,10996);
    INSERT INTO     caln
    VALUES (To_Date('02/08/2010','mm/dd/yyyy'),2010,26,To_Date('02/08/2010','mm/dd/yyyy'),6,2010,7657,10997);
    INSERT INTO     caln
    VALUES (To_Date('02/09/2010','mm/dd/yyyy'),2010,27,To_Date('02/09/2010','mm/dd/yyyy'),6,2010,7658,10998);
    INSERT INTO     caln
    VALUES (To_Date('02/10/2010','mm/dd/yyyy'),2010,28,To_Date('02/10/2010','mm/dd/yyyy'),6,2010,7659,10999);
    INSERT INTO     caln
    VALUES (To_Date('02/11/2010','mm/dd/yyyy'),2010,29,To_Date('02/11/2010','mm/dd/yyyy'),6,2010,7660,11000);
    INSERT INTO     caln
    VALUES (To_Date('02/12/2010','mm/dd/yyyy'),2010,30,To_Date('02/12/2010','mm/dd/yyyy'),6,2010,7661,11001);
    INSERT INTO     caln
    VALUES (To_Date('02/13/2010','mm/dd/yyyy'),2010,0,To_Date('02/12/2010','mm/dd/yyyy'),6,2010,7661,11002);
    INSERT INTO     caln
    VALUES (To_Date('02/14/2010','mm/dd/yyyy'),2010,0,To_Date('02/12/2010','mm/dd/yyyy'),7,2010,7661,11003);
    INSERT INTO     caln
    VALUES (To_Date('02/15/2010','mm/dd/yyyy'),2010,31,To_Date('02/15/2010','mm/dd/yyyy'),7,2010,7662,11004);
    INSERT INTO     caln
    VALUES (To_Date('02/16/2010','mm/dd/yyyy'),2010,32,To_Date('02/16/2010','mm/dd/yyyy'),7,2010,7663,11005);
    INSERT INTO     caln
    VALUES (To_Date('02/17/2010','mm/dd/yyyy'),2010,33,To_Date('02/17/2010','mm/dd/yyyy'),7,2010,7664,11006);
    INSERT INTO     caln
    VALUES (To_Date('02/18/2010','mm/dd/yyyy'),2010,34,To_Date('02/18/2010','mm/dd/yyyy'),7,2010,7665,11007);
    INSERT INTO     caln
    VALUES (To_Date('02/19/2010','mm/dd/yyyy'),2010,35,To_Date('02/19/2010','mm/dd/yyyy'),7,2010,7666,11008);
    INSERT INTO     caln
    VALUES (To_Date('02/20/2010','mm/dd/yyyy'),2010,0,To_Date('02/19/2010','mm/dd/yyyy'),7,2010,7666,11009);
    CREATE TABLE ords
    (     ord_nbr          NUMBER          NOT NULL
    ,     sub_nbr          NUMBER          NOT NULL
    ,     ord_stat     VARCHAR2(2)
    ,     ord_qty          NUMBER
    ,     part_nbr     VARCHAR2(5)
         CONSTRAINT ords_pk PRIMARY KEY (ord_nbr, sub_nbr)
    INSERT INTO     ords
    VALUES (1,1,'CL',10,'PART1');
    INSERT INTO     ords
    VALUES (1,2,'CL',5,'PART1');
    INSERT INTO     ords
    VALUES (25,1,'CL',15,'PART2');
    INSERT INTO     ords
    VALUES (14,1,'OP',12,'PART3');
    INSERT INTO     ords
    VALUES (33,1,'CL',25,'PART1');
    INSERT INTO     ords
    VALUES (33,2,'CL',15,'PART1');
    INSERT INTO     ords
    VALUES (33,3,'OP',10,'PART1');
    INSERT INTO     ords
    VALUES (7,1,'PL',18,'PART2');
    INSERT INTO     ords
    VALUES (96,1,'PL',10,'PART3');
    INSERT INTO     ords
    VALUES (31,1,'CL',20,'PART2');
    CREATE TABLE oops
    (     ord_nbr          NUMBER          NOT NULL
    ,     sub_nbr          NUMBER          NOT NULL
    ,     op_nbr          VARCHAR2(4)     NOT NULL
    ,     mach_id          VARCHAR2(4)
    ,     oper_stat     VARCHAR2(2)
    ,     plan_start_dt     DATE
    ,     plsu          NUMBER
    ,     plrn          NUMBER
         CONSTRAINT ords_pk PRIMARY KEY (ord_nbr, sub_nbr, op_nbr)
    -- NOTE:
    -- for the orders with a status of 'CL' or 'PL' in the 'ords' table, I'm not bothering to put
    -- in more than two operations (though in reality more would be there) since they should be
    -- ignored in the final result anyway
    INSERT INTO     oops
    VALUES (1,1,'0010','123A','CL',TO_DATE('01/11/2010','mm/dd/yyyy'),2,0.2);
    INSERT INTO     oops
    VALUES (1,1,'0015','259B','CP',TO_DATE('01/12/2010','mm/dd/yyyy'),1,0.15);
    INSERT INTO     oops
    VALUES (1,2,'0010','123A','CP',TO_DATE('01/11/2010','mm/dd/yyyy'),2,0.2);
    INSERT INTO     oops
    VALUES (1,2,'0015','259B','CP',TO_DATE('01/12/2010','mm/dd/yyyy'),1,0.15);
    INSERT INTO     oops
    VALUES (25,1,'0005','123A','CP',TO_DATE('01/18/2010','mm/dd/yyyy'),2,0.25);
    INSERT INTO     oops
    VALUES (25,1,'0030','110C','CL',TO_DATE('01/19/2010','mm/dd/yyyy'),4,0.1);
    INSERT INTO     oops
    VALUES (14,1,'0010','127A','CP',TO_DATE('01/11/2010','mm/dd/yyyy'),2,0.25);
    INSERT INTO     oops
    VALUES (14,1,'0025','110C','CL',TO_DATE('01/12/2010','mm/dd/yyyy'),1,0.1);
    INSERT INTO     oops
    VALUES (14,1,'0040','050C','CP',TO_DATE('01/13/2010','mm/dd/yyyy'),1.3,0.15);
    INSERT INTO     oops
    VALUES (14,1,'0050','220B','WK',TO_DATE('01/14/2010','mm/dd/yyyy'),4,0.25);
    INSERT INTO     oops
    VALUES (14,1,'0065','242B','AV',TO_DATE('01/18/2010','mm/dd/yyyy'),1.5,0.1);
    INSERT INTO     oops
    VALUES (14,1,'0067','150G','NA',TO_DATE('01/19/2010','mm/dd/yyyy'),2,0.1);
    INSERT INTO     oops
    VALUES (14,1,'0100','250G','NA',TO_DATE('01/20/2010','mm/dd/yyyy'),2.1,0.2);
    INSERT INTO     oops
    VALUES (33,1,'0010','123A','CL',TO_DATE('01/11/2010','mm/dd/yyyy'),1.9,0.2);
    INSERT INTO     oops
    VALUES (33,1,'0015','259B','CP',TO_DATE('01/12/2010','mm/dd/yyyy'),1,0.1);
    INSERT INTO     oops
    VALUES (33,2,'0010','123A','CL',TO_DATE('01/11/2010','mm/dd/yyyy'),1.9,0.2);
    INSERT INTO     oops
    VALUES (33,2,'0015','259B','CP',TO_DATE('01/12/2010','mm/dd/yyyy'),1,0.1);
    INSERT INTO     oops
    VALUES (33,3,'0010','123A','CL',TO_DATE('01/11/2010','mm/dd/yyyy'),1.9,0.2);
    INSERT INTO     oops
    VALUES (33,3,'0015','259B','CP',TO_DATE('01/12/2010','mm/dd/yyyy'),1,0.1);
    INSERT INTO     oops
    VALUES (33,3,'0020','220B','NA',TO_DATE('01/12/2010','mm/dd/yyyy'),1.7,0.15);
    INSERT INTO     oops
    VALUES (33,3,'0030','150G','NA',TO_DATE('01/13/2010','mm/dd/yyyy'),1.3,0.05);
    INSERT INTO     oops
    VALUES (33,3,'0055','150G','NA',TO_DATE('01/15/2010','mm/dd/yyyy'),2.1.,0.1);
    INSERT INTO     oops
    VALUES (7,1,'0005','123A','NA',TO_DATE('01/11/2010','mm/dd/yyyy'),2,0.2);
    INSERT INTO     oops
    VALUES (7,1,'0030','110C','NA',TO_DATE('01/12/2010','mm/dd/yyyy'),1,0.15);
    INSERT INTO     oops
    VALUES (96,1,'0010','127A','NA',TO_DATE('01/11/2010','mm/dd/yyyy'),2,0.25);
    INSERT INTO     oops
    VALUES (96,1,'0025','110C','NA',TO_DATE('01/12/2010','mm/dd/yyyy'),1,0.1);
    INSERT INTO     oops
    VALUES (31,1,'0005','123A','CL',TO_DATE('01/11/2010','mm/dd/yyyy'),1.9,0.2);
    INSERT INTO     oops
    VALUES (31,1,'0030','110C','CP',TO_DATE('01/12/2010','mm/dd/yyyy'),1,0.1);
    CREATE TABLE mach
    (     mach_id          VARCHAR2(4)     NOT NULL
    ,     desc_short     VARCHAR2(9)     
    ,     group          VARCHAR2(7)
         CONSTRAINT ords_pk PRIMARY KEY (mach_id)
    INSERT INTO     mach
    VALUES     ('123A','desc here','GROUPH1');
    INSERT INTO     mach
    VALUES     ('259B','desc here','GROUPH2');
    INSERT INTO     mach
    VALUES     ('110C','desc here','GROUPJ1');
    INSERT INTO     mach
    VALUES     ('050C','desc here','GROUPK2');
    INSERT INTO     mach
    VALUES     ('220B','desc here','GROUPH2');
    INSERT INTO     mach
    VALUES     ('242B','desc here','GROUPH2');
    INSERT INTO     mach
    VALUES     ('150G','desc here','GROUPL1');
    INSERT INTO     mach
    VALUES     ('250G','desc here','GROUPL2');
    INSERT INTO     mach
    VALUES     ('242B','desc here','GROUPH2');

Maybe you are looking for

  • Can you make some columns Read/Display Only in DataSheet view?

    I noticed on another posting what appears to be a datasheet view with 3 of the columns in a display mode. Can someone confirm if this is possible? Here is the original posting. http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomizationprev

  • Why is the library Menu is gray?

    Why the menu on the left side of the iphoto is gray and not color?

  • FB05 clearing item

    Hi, is it possible with FB05 to run clearing for a single line item of a FI document or do I have to run clearing for the all document? If it possible to run clearing for a single line item, how can I do it? Regards and thank you for your time Norber

  • Proportionaly scaling down background image when restoring down browser window

    Hi all, i need some help, i want to minimize(scale or restore down) window to not-fullscreen browser window (and ajusting size of window manually over arrows in the corners of the window) and retain background picture full size (i need to picture pro

  • Flash paper divison3d publish error

    flash paper divison3d publish error..chk dis link http://www.nirav.dataintl.co.in/error/