SELECT LINES FROM TOP TO BOTTOM UNTIL RUNNING TOTAL = SOME_VALUE

In the example below, I will select rows from top until my cumulative total of PAYAMOUNT is less than or equal to 40000

ID RATE DATE ORGAMNT PAYAMOUNT

1 3.23 12/12/12 23000,45 13000.00

2 4.55 30/05/11 40000,55 26000.00

3 6.78 21/03/14 60000,00 60000.00

My output table must be

ID RATE DATE ORGAMNT PAYAMOUNT

1 3.23 12/12/12 23000,45 13000.00

2 4.55 30/05/11 40000,55 26000.00

Appreciate your help.

Kind regards.

Hello

This sounds like a job for the analytical SUM function.

As you post CREATE TABLE and INSERT statements for your data, I will illustrate using the table scott.emp, which is probably on your system.

Scott.EMP contains the ename, hiredate and sal columns below:

ENAME HIREDATE RUNNING_TOTAL SAL

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

SMITH, 17 December 1980 800 800

ALLEN 20 February 1981-1600-2400

February 22, 1981 DISTRICT 1250 3650

JONES, 2 April 1981 2975 6625

May 1, 1981 BLAKE 2850 9475

CLARK 9 June 1981 2450 11925

13425 1500 08 - Sep - 1981 TURNER

MARTIN 28-Sep-1981 1250 14675

5000 17 November 1981 KING 19675

JAMES 3 December 1981 950 23625

FORD 3000 3 December 1981 23625

MILLER, January 23, 1982 1300 24925

SCOTT on April 19, 1987 3000 27925

ADAMS, 23 May 1987 1100 29025

Now, let's say, we want to show that the first lines (in order by hiredate) where the total sal is not more than 10000.  One way to do that would be to use the SUM function to calculate the running_total above column and use running_total in a WHERE clause, the results below:

ENAME SAL HIREDATE

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

SMITH, 17 December 1980 800

ALLEN 20 February 1981 1600

DISTRICT 1250 22 February 1981

JONES, 2 April 1981 2975

May 1, 1981 BLAKE 2850

Here's a way to do it:

WITH got_running_total AS

(

SELECT ename, hiredate, sal

SUM (sal) over (ORDER BY hiredate) AS running_total

FROM scott.emp

)

SELECT ename, hiredate, sal

OF got_running_total

WHERE running_total<=>

ORDER BY hiredate

;

The subquery is necessary because the analytic functions are calculated after the WHERE clause has been applied.  If we want to use the results of an analytic function in a WHERE clause, you must calculate the function in a subquery (as got_running_total, above).

Tags: Database

Similar Questions

  • CN460A: ADF print copy with a thin line from top to bottom?

    ADF print copy with a thin line from top to bottom of page.  fine prints from the PC to the printer...

    This was probably caused by a specification on the thin glass used for scanning form the ADF.  See here for more information on cleaning this area to solve printing line when using the ADF.

  • Satellite P845-Canada-10J - HDMI to TV - horizontal lines from top to bottom

    During video playback through HDMI to my TV, I get horizontal lines from top to bottom.

    I tried to change the refresh rate, change the cables, evolution of videos of different ports and video and all players the same. I have a Hannspree 32 inch 1080 p which supports 50 Hz and 60 Hz.

    Any ideas on how to fix this?

    and are not the same visible lines on another screen or internal monitor?
    Laptop Satellite P845-Canada-10J seems to also support the RGB (VGA) port you could try connecting the monitor to this port just to check if the same lines are visible using another video interface

  • OfficeJet Pro 8500 has vertical line from top to bottom after a copy or scanning via adf

    Each copy or scan do using the automatic document feeder to my HP Officejet Pro 8500 a shows a vertical line from top to bottom left of each page. I have cleaned the printer at all parts of the feeder, - nothing dirty in fact found. When I copy or scan the glass plate there is no vertical line on paper.

    Anyone have the same experience with this printer?

    Usually if the scanner works on the dish, but product line in the scans from the ADF, it's because of something on the glass.  Have you tried to shine a flashlight down on the surface of the small approximately 1 in. piece of glass on the left side of the bucket?  This is the strip of glass used for the ADF.

    Like trying to clean the white strip, located on the lid above the glass of the ADF, well clean to make sure there is no debris on the support that can cause this line appears.

    * Make sure that the printer is plugged into a direct socket, rather than a surge protector.  The 8500 has protection against overvoltages integrated in the device and an another surge in the circuit protector can sometimes cause lines.  However, usually this causes lines in both ADF and flatbed scans.

    There is also a document provided by HP with the steps to troubleshoot issues when a line is present in the copies/scans.  The document can be accessed here.

    I hope this helps.

  • How is - what cut you a rectangle in 2 colors with a diagonal from top to bottom?  Once I draw a diagonal with the online tool I am at loss to create 2 color split?

    How is - what cut you a rectangle in 2 colors with a diagonal from top to bottom?  Once I draw a diagonal with the online tool I am at loss to create 2 color split?

    Rosemary,

    A simple way would be to:

    (1) give the rectangle a color, then Ctrl > Cmd + C + F;

    (2) use the direct Selection tool, and then deselect (click and empty space), then click on the opposite corner to the part where you want to keep the color, then press DELETE, then change the fill color to the other.

    Or, you can ClickDrag with the line tool along the diagonal line from corner to corner (guides are your friends), select it all and Pathfinder > divide, then select live from the triangle where you want to change the color and change.

  • Is it possible that I can have my background scroll from top to bottom of the image

    Original title: scrolling background

    One of my friends has recently done a photo for me I would really like to have as my background, but it is very vertical. Is it possible that I can have my background scroll from top to bottom of the picture and then go back to the top?

    Backgrounds can not move, don't.

  • Illustrator text on a path with a gradient from top to bottom?

    Try to get a gradient to text on a wavy path.

    I found problems / very similar answers, but not quite this one...

    I'm creating a poster. There the text of PROGRAM of COMPOSTING MUNICIPAL BACKYARD (2 lines, backyard CITED above, then of COMPOSTING PROGRAM below)

    The text has a light brown dark brown gradient running up and down on the whole text.

    The text is on a green background.

    They now want the green background to be a banner wave, and the text is inside the banner and follow the wavy shape of the banner.

    And of course that the gradient must follow the wavy form of the text, so the tops of letters are the same light brown and the bottom of all the letters are the same despite Brown, dark letters are flowing up and down along the wavy shape of the banner.

    I received my text as a result of the wave of the banner, and I have a version with the text now changed to the railways (and a composite path because it's two lines), but of course when I apply the gradient, the gradient runs directly through the letters instead of follow the wave.

    Is there a way to do this? I found a method of creating a mixture and stroke following forms apply it as an accident, but not what I have to do here.

    Thank you!

    Quoz,

    I think it is easier and better use a combination of follows, with the two curved lines of direct Type (especially if they have Anchor Points (numbers of) correspondent):

    (A) direct select both the path of nofill who wear both sets of Type, then Ctrl / Cmd + X + B to bring to the back, then give them a fill and lock the Type of path together.

    (B) attach the ends of the two lines so that they form a something like a distorted rectangle (you can select directly the end corresponding units);

    (1) object > path > offset path by the distance down to the top of the text up/down the low text, this should give you a closed path extra with straight segments end;

    ((2) directly select the straight end of the segments and remove them with the winding of B rectangle), this should give you a line of top and a bottom line.

    (3) give up and down the color that you want at the top of the letters above and below the letters down, the lines then object > mix > blend Options, with the smooth settings and align on the track, this should give you the transition of color behind the original lines;

    (4) to unlock, then select the two curved lines of the Type and the object > compound path > make if not already;

    (5) select the Type (Path) alive and the color transition and object > clipping mask > make.

  • Can I extend the horizontal slide show in a straight line but not full page from top to bottom?

    Can I extend the horizontal slideshow in a straight line on the page from start to finish, but not full page up and down?

    Hello

    Please check these videos to help:

    https://www.YouTube.com/watch?v=BDgERSf2a5k

    https://www.YouTube.com/watch?v=diUtfwFGI1w

    Thank you

    Sanjit

  • Satellite A100: Thin yellow line on the screen from top to bottom

    Since this afternoon here a thin yellow line up and down on the left side of the screen. Reset does not work. It is already there, when I start my laptop. Anyone have any idea what it is? Thank you.

    Hello

    For me, it's like something wrong with the hardware.
    The Satellite A100 is a new model of laptop and I guess you laptop is covered by the warranty.
    I recommend you contact Toshiba service partner in your country.
    Explain the display problem and I? m ensure that guys will help you.

  • How to: move the taskbar from top to bottom

    Original title : How can I move my taskbar to the top to the bottom?  Have no idea how it got there.  Have a netbook and a touchpad.  THX.

    Please see section.  That's all!  Have never locked the taskbar.

    Right click on the Start button. Properties | Tab taskbar | Location of the taskbar on the screen. Carry out the adjustment.
  • Computer laptop screen goes from top to bottom and back randomly.

    I recently bought a HP Pavilion notebook 15-n010us.  I have problems with the light constantly gradation from the bottom up and vice versa.  This problem persists regardless of the power supply or ambient light.  This model has an automatic dimming of the sensor for the backlight?  If so, how can I disable it.  If this isn't the case, I have a question/fault with the laptop backlight?

    Thanks for your help!

    Did some searching HP forums and found the solution here.  So far, the solution works.  I bring here if it doesn't.

  • How to hide a photo from top to bottom

    I have CS5

    I want to have a visible image to fade it and Slowey to transparency down.

    any help please.

    Hello! Here is a step by step to achieve a fade image on transparency:

    Here is the image I want to fade to transparency.

    In the layers panel, press the icon for mask down, as shown below.

    You can see that in the layers panel, a mask is now attached to my image.

    In the toolbar, make sure that you have the black selected, as shown below.

    Then go and select the brush from the toolbar.

    With the brush, paint the black on the mask. This will remove the image where you paint, revealing transparency below.

    To give a more uniform transition between image and transparency, go to filter > blur > Gaussian blur

    The Gaussian blur dialog box will appear. Adjust accordingly.

    Here is my finished image.

    I hope this has helped!

    Janelle flores

  • print from top to bottom

    I have a HP 7510 with a duplexer, computer is running windows XP.  My question is how to set it up to high rpint in bottob on both sides of the paper?  Help, please.

    Hello

    Of suggestions print (or print properties), please try this:

    Kind regards.

    PS. Sorry, the image shows print last page first.

  • Access points dropping from top to bottom

    I have anywhere from 5 to 20 points of access drop goes up and down all day on a total of about 200. I try currently to cross and understand why we our access points are conducting many issues and how I might be able to solve.

    One of the newspapers I see often is:

    AP "exp - p13,' interface '802. ' 11A ' controller ' 10.2.192.25 '. String passed to ' 44 ""60"due to 'None '. Energy interference before update is ' 0 'and after update is ' 0'. Noise before update is ' 0 'and after that update is ' 0'. Interference before update is ' 0 'and after update is ' 0'.

    Is any way to determine what the cause of this?

    The controller firmware: 4.2.130.0.

    Model AP-AIR-LAP1242AG-A-K9

    IOS Version 12.4 (10B) JA4

    Sounds as if it was just the Radio Resource Management (RRM) on the controller. You can disable this if she is down to customers. Go to the wireless tab, look on the left and click on the 802. 11A / n or 802.11b/g/n dropdown. Then click on the drop down RRM, click Auto RF.

    My advice is to change the algorithms of subpoena power and channel to "On Demand. You can call them to the need to maintain an optimal network. By default, it automatically calls the update every 10 minutes.

    Give it a try and see if it helps. If this isn't the case, we can explore more.

  • His continues to go from top to bottom.

    The volume on my laptop has been going up and down constantly for the last two days and it drives me crazy. I reinstalled my driver audio, from virus and don't take away please help. If it helps I have a hp pavilion dv5.

    Go to control panel > programs and features and remove smart MediaSmart Menu program...

    Download and install from HERE

Maybe you are looking for

  • I opened ink invisible messeges

    When I receive messages in invisible ink, they come already open with just the text under it saying that it has been sent to invisible ink.

  • FBI wants $400 to unlock browser

    I was on a porn site, and then suddenly the screen filled with a FBI telling me I have to pay $400 to unlock my browser. I tried to get out, but I couldn't just kept reloading page. I had to turn off the power to the computer in order to stop, then d

  • Profile of the home screen layout

    Hello I just want to create a layout of the home screen setting profile Builder 2 for iOS 9.3. But I have a question on connect. The field 'Pages' are not valid. Here is my demo profile: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "

  • Sansaclip left my player without any songs firmware update

    I installed the firmware update yesterday and when I unjacked my sansaclip of my laptop and pressed on "songs", he says only 'empty '. But when I plugged back on my laptop and my music folder is clicked, all my songs were there. What is the problem w

  • Much more time gap between tracks using the latest firmware.

    Everyone has noticed there is now a gap of 5 or 6 seconds between tracks because they have updated their firmware to the latest version? It was about 1 second. Is it just me or is this a known problem? If the latter is their a workaround? Thank you v