How do I report the results of the previous record to the next record in a query

Hello

For example if I have data of the table as.

AC_CODE DATE CREDIT DEBIT

----------------------------------

1001 15 APRIL 15 10

1001 APRIL 25, 15 2

1005 5 APRIL 15 100

1005 8 APRIL 15 25

----------------------------------

And I want to train as below, where, BALANCE = (previous record BALANCE) + CREDIT - DEBIT

(assuming that NVL (, 0) for all columns)

(assuming the BALANCE reset after change of AC_CODE)

DATE AC_CODE CREDIT DEBIT BALANCE

--------------------------------------------

1001 15 APRIL 15 10 10

1001 APRIL 25 15 2 8

1005 5 APRIL 15 100 - 100

1005 8 APRIL 15 25 - 75

--------------------------------------------

(AC_CODE ORDER, DATE)

Of course, it can be reached using query of database function.  My question is, is it possible by using a query without involving all functions.

Thank you

-Anand

Model clause could help you meet this goal...

Note: There is a separate area for SQL, PL/SQL issues here in OTN and don't forget to provide insertion, create scripts for your sample data for a quick response

with t as(select 1001 AC_CODE,to_date('15-APR-2015','DD-MON-yyyy') dt,10 credit,null debit from dual union all
          select 1001,to_date('25-APR-2015','DD-MON-yyyy'),null,2 from dual union all
          select 1005,to_date('05-APR-2015','DD-MON-yyyy'),null,100 from dual union all
          select 1005,to_date('08-APR-2015','DD-MON-yyyy'),25,null from dual
        )
    select ac_code
          ,dt
          ,credit
          ,debit
          ,balance
        from t
        model
            partition by (ac_code)
            dimension by (row_number() over(partition by ac_code order by dt) rn)
            measures (dt,credit,debit,0 as balance)
            rules
                (
                    balance[any] = nvl(balance[cv()-1],0) + nvl(credit[cv()],0) - nvl(debit[cv()],0)
                )
        ;

Tags: Database

Similar Questions

  • How can I disable the next/previous button at the bottom left of the Windows Picture and Fax

    I am a beginner of the windows developer, please help me.

    1. How can I disable the next/previous button at the bottom left of the Windows Picture and Fax Viewer? E.g. change Registory or others...
    2. when I click the print on the Windows Picture and Fax Viewer, the image of the current directory

    will appear in print wizard, how can I show only the currently shoing image?

    Note: windows XP SP3

    Hi NewsAru,

    Unfortunately, there is no way to disable the next\previous buttons in Windows Picture and Fax Viewer.

    When you try to print an image by using Windows Picture and Fax Viewer it would display all available photos in the folder that contains the image you have chosen to print.

    Overview of Windows Picture and Fax Viewer

    http://www.Microsoft.com/resources/documentation/Windows/XP/all/proddocs/en-us/image_toolbar.mspx?mfr=true

  • How to navigate to the next page based on the value returned by the method call inside the action attribute of the command key.

    How to navigate to the next page based on the value returned by the method call inside the action attribute of the command key.

    I use JDeveloper 12.1.2.0.0

    < af:button id = "tt_b2".

    rendered = "#{attrs.nextRendered} '"

    partialSubmit = 'true '.

    action = "#{attrs.backingBean.nextAction} '"

    Text = "next".

    Disabled = "#{attrs.nextDisabled}" / >

    private static final String NEXT_NAVIGATION_ACTION = "controllerContext.currentViewPort.taskFlowContext.trainModel.getNext";

    public String nextAction() {}

    If (validate()) {}

    updateModel();

    Return NEXT_NAVIGATION_ACTION;

    }

    Returns a null value.

    }

    Use case is made for model train, which is being implemented based on this blog: http://javacollectibles.blogspot.co.UK/2014/10/ADF-train-template.html

    We define a generic action following in the model, but the action must be called under certain conditions, based on the question of whether all validation controls had been passed on no.

    You can do this in two ways:

    1 returnValue = (String) ADFUtils.invokeEL("#{controllerContext.currentViewPort.taskFlowContext.trainModel.getNext}");

    return returnValue;

    2.

    public String getNextTrainStop() {}

    String nextStopAction = null;

    ControllerContext controllerContext = ControllerContext.getInstance ();

    ViewPortContext currentViewPortCtx = controllerContext.getCurrentViewPort ();

    TaskFlowContext taskFlowCtx = currentViewPortCtx.getTaskFlowContext ();

    TaskFlowTrainModel taskFlowTrainModel = taskFlowCtx.getTaskFlowTrainModel ();

    TaskFlowTrainStopModel currentStop = taskFlowTrainModel.getCurrentStop ();

    Terminus of TaskFlowTrainStopModel = taskFlowTrainModel.getNextStop (currentStop);

    nextStopAction = nextStop.getOutcome ();

    _logger.fine ("train, next stop:"+ nextStopAction ");

    Return nextStopAction;

    }

  • I just need a tutorial step by step on how to move to the next upgrade, ex: 4.0 NOT to the newest one, thank you.

    I don't know where to go to get to the next level when the office is saying that the level I am sure will soon expire. Can I upgrade before its expiry, a new level NOT the newest one and how do I do it?

    Firefox 3.6 will probably be supported until April 2012. Firefox 4, 5, 6, 7 and 8 don't are not supported any longer, only 3.6.25 and 9.0.1.

  • When changing the windows, how can I get the next window full screen?

    I double click on my ebay icon, it opens in a window that is minamised. How can I configure it to mount the best?

    Try this:

    Open it shortcut-> close all other windows internet Explorer-> drag the edges of the window to fill the entire screen-> close the window by holding the 'alt' key and clicking on the button close at the top right of the window (red with white "x" button), the next time that you open, you should remember its size when it was closed.

    I hope I could help

  • How to move to the next component?

    Dear friends,

    Can someone tell me how to move the focus to the next item in the screen. In fact, I have a verticalmanager with verticalscroll this Manager of vertical field consists of the field with about 100 rows of data. Below this vertical field Manager, I have a single button. If I want to move this button means that I have to go through all these 100 lines in this edit field. It is in any case to move the focus to the button directly by clicking the single button. If you have an idea to solve this problem pls help if you can please give me some code snippet.

    Kind regards

    s.Kumaran.

    You can use setFocus to set focus on a certain area. How you trigger it is your choice, you could, for example, use enter or alt + key. Use keychar or keydown for the management of keys.

  • How to go to the next section press the right key

    Hi, I need script to the next section Stop when the user presses the right key

    and press the button on the left for Goto Prev frame

    This script works well but that's THE key can also be used

    stage.addEventListener (KeyboardEvent.KEY_UP, keyHandler);

    function keyHandler(e:KeyboardEvent):void

    {

    nextFrame();

    }

    and KEY_RIGHT, KEY_LEFT does not work.

    I try to use Key.getCode () and 37 and 39 of the code, but I have no idea how to use.

    Thank you

    you have to

    import flash.ui.Keyboard

    then you can write

    function keyHandler(e:KeyboardEvent):void

    {

    {Switch (e.keycode)}

    -case Keyboard.RIGHT: nextFrame (); break;

    case Keyboad.LEFT:prevFrame (); break

    }

    }

  • How to go to the next slide during Drag and Drop

    I'm trying to go automatically to the next slide after the user makes a three 'drop zone' drag and drop.

    I see the action on the successes in the Panel. I chose to go to the next slide, but nothing happens after I have test.

    I also put in place the right answers for the drop areas three and thought that could trigger the part of "success."

    but still nothing happens.

    Any thoughts?

    Hi again,

    I understand, but in order to move to the next slide automatically the drag and drop must be introduced. It doesn't matter whether or not you include your drag and drop in a quiz. The option to send automatic drag / move it will include not a quiz, is to check if the answers are correct or not. You can leave to include it in an unchecked quiz.

    Thank you!

  • How can I use the lead/lag in this query

    I wrote this query that gives me the comparative data based on this week and next week. How is the lead/Lag used in this query.
       WITH CURRENT_WEEK
              AS (  SELECT   QPAQ.YEAR YEAR,
                             QPAQ.SEASON SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+') ACC_SERIES,
                             TO_NUMBER (QPAQ.WEEK) WEEK,
                             MAX (QPAQ.FAILURES) FAILURES
                      FROM   QAR_PLAN_ACC_QTY QPAQ, QAR_PLAN_THRESHOLD_LST QPTL
                     WHERE       QPTL.CATEGORY_ID = 7
                             AND QPAQ.YEAR = QPTL.YEAR
                             AND QPAQ.SEASON = QPTL.SEASON
                             AND QPAQ.SERIES_NAME = QPTL.MODEL_SERIES
                  GROUP BY   QPAQ.YEAR,
                             QPAQ.SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+'),
                             TO_NUMBER (QPAQ.WEEK)
                  ORDER BY   REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+')),
           LAST_WEEK
              AS (  SELECT   QPAQ.YEAR YEAR,
                             QPAQ.SEASON SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+') ACC_SERIES,
                             TO_NUMBER (QPAQ.WEEK + 1) WEEK,
                             MAX (QPAQ.FAILURES) FAILURES
                      FROM   QAR_PLAN_ACC_QTY QPAQ, QAR_PLAN_THRESHOLD_LST QPTL
                     WHERE       QPTL.CATEGORY_ID = 7
                             AND QPAQ.YEAR = QPTL.YEAR
                             AND QPAQ.SEASON = QPTL.SEASON
                             AND QPAQ.SERIES_NAME = QPTL.MODEL_SERIES
                  GROUP BY   QPAQ.YEAR,
                             QPAQ.SEASON,
                             REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+'),
                             TO_NUMBER (QPAQ.WEEK)
                  ORDER BY   REGEXP_SUBSTR (QPAQ.SERIES_NAME, '[^/]+'))
         SELECT   CURRENT_WEEK.YEAR,
                  CURRENT_WEEK.SEASON,
                  CURRENT_WEEK.ACC_SERIES,
                  CURRENT_WEEK.WEEK,
                  CURRENT_WEEK.FAILURES,
                  (CURRENT_WEEK.FAILURES - LAST_WEEK.FAILURES) FAILURES_COMPARE
           FROM   LAST_WEEK, CURRENT_WEEK
          WHERE   CURRENT_WEEK.WEEK = LAST_WEEK.WEEK(+)
       ORDER BY   CURRENT_WEEK.WEEK;
    Output is like this.
                    YEAR         SEASON     MODEL                     WEEK        FAILURES    Failures_COMPARE
    1     2011     SUMMER     VGP-BMS15     49     10     
    2     2011     SUMMER     VGP-BMS15     50     28       18
    3     2011     SUMMER     VGP-BMS15     51     30       2
    4     2011     SUMMER     VGP-BMS15     52     40       10
    Edited by: BluShadow January 6, 2012 13:26
    addition of {noformat}
    {noformat} tags. Please read {message:id=9360002} to learn to do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

    You would dump the subquery LAST_WEEK together. Then replace the calculation of your failure with

        current_week.failure - lag(current_week.failure) over (order by current_week.year, current_week.week) as failures_compare
    

    I guess you might want to think about renaming the subquery as well...

    Cheers, APC

    Published by: APC on 6 January 2012 13:41

  • How to get to the next section in a clip inside another video clip

    I have a master clip that my entire Web page is located, called masterMC.  If I double click on it, I've got another clip from movie called transitionMC.  I want to advance the timeline in masterMC when transitionMC ends of reading, but not at the root level.  I want to move the MasterMC, not the root timeline.  How can I do this?

    That's what I used:

    Stop();

    If (MovieClip (root) .currentFrame<>

    MovieClip (root) .nextFrame ();

    }

    I replaced (root) with parent.  It has worked well.  Thank you!

  • How to move to the next item of selected in a list.

    * Edition *.

    I was wondering how I could make a button that would move the currently selected item to another in the array in a List component. I would think to do so through of ACE or an event, but I only am not sure what I have référenceriez under this component. Help would be appreciated, thanks.

    You can set the selectedIndex property. What next button increments the selectedIndex property.

    If (list.selectedIndex< list.dataprovider.length="" -="" 1="">

    list.selectedIndex ++;

  • How to continue to the next page after that a preloader is loaded

    I did a preloader to my website in flash cs4. I imported into dreamweaver and it works but I can't get it to contiune to the real homepage after he's done loading. Does anyone know how to do this?

    From what I saw on this site, people who have negative things to say about this make sense better than those who praise.  I'm guessing that you're not actually preload anything whatever, and this file is just acting as a kind of Visual effect for your site.  As a preloader, this must be integrated into a web site, Flash and would load the file in the site.

    Anyway, to get it to go to your home page, replace the following line in the onComplete function...

    trace ("Loaded!");

    with...

    navigateToURL (new URLRequest ("http://www.yourdomain.com/yourpage.html"), "_self");

  • How can I get the next message in my Inbox?

    I am a new user of Thunderbird. I am going through the mails in my Inbox. I finished reading the first e-mail, now want to go to the following e-mail address. I don't see any button to access the following email, or an "arrow" or something else, this allows me to do. The answer is probably ridiculously easy, but I'm not. Help, please.

    It would depend on where you view your messages.

    If you use the component messages, in my opinion the easiest, top and down arrows work very well.
    You switch the message pane on / off power with the F8 key.

    If you open your messages in a new tab or window by double clicking on them you must learn the shortcuts.

    N = next unread message
    F = message (forward)

    P = message unread precedent
    B = the previous message (back)

  • How to set up the next book.

    Separated from this thread.

    Someone will be kind enough to help me

    set up my next book? I need HELP!

    PLEASE, I BEG YOU.

    Hello

    OEM NextBook is responsible for the functioning Windows and hardware
    so, they should be able to help.

    NextBook
    http://nextbookusa.com/index.php

    NextBook - downloads - manual
    http://nextbookusa.com/download.php

    NextBook - Support
    http://support.nextbookusa.com/support/

    Apps - contact us
    http://nextbookusa.com/contactus.php

    I hope this helps.

    Rob Brown - Microsoft MVP<- profile="" -="" windows="" expert="" -="" consumer="" :="" bicycle="" -="" mark="" twain="" said="" it="">

  • How to 'tab' to the next object

    I am above all a Flash developer, and I'm used to the tab between the objects on the stage. I got art of a designer who I am cleaning for import in Flash. Many of these files have "stuff" in a group causes the group to be more physically it is visually. I can click on each object in the layers panel to understand which is the offending object, but it would be more easy/fast if I could use the keyboard to scroll through the items. Y at - it a keyboard shortcut that works for this? Tab in Illustrator has rather alarming affects.

    # Handling of objects AI is totally arbitrary and internal ID does not follow a linear logic that would allow cycling through them with all the keys.

    Mylenium

Maybe you are looking for

  • Mid-2009 MBP memory is compatible with the iMac late 2009?

    Hello I just upgraded the memory for my MacBook Pro (from 2 X 2 GB 2 X 4 GB)... I was going to sell the used memory space but realized that I might be able to add to my iMac late 2009.  How will I know if it's compatible?  Currently the iMac only has

  • Constantly reauthorizing TV channel apps!

    We have 3 ATV3 and with all units, we will have to reauthorize all apps from channel TV, history, A & E, ESPN, FXNOW, FOXNOW and many others, about all the 2 weeks. Is it still occurring with the latest ATV4? Is it a problem to Apple or a cable provi

  • WWAN in X 300

    I know that some X 300 comes with a Verizon WWAN card already installed. AT & T makes one that could serve as a replacement? Or wouldn't be something so simple as just switching providers? Thank you Kevin

  • How to install LabVIEW 7.0 on PXI-8186 RT

    I try to install LabVIEW 7.0 in real-time on a PXI-8186 controller.  It took a lot of time to go through the process, and it still does not, so I write this message in part to help and partly to document which does not work for later use.  The contro

  • HP envy m6: BIOS Password Reset

    Forgot the password of the BIOS on this laptop, and I need a PIN to work around and remove/reset the BIOS password. I pressed on enter 3 times to get a "system disabled" # of 96257035. Help, please! Thank you.