How to get the difference of current and previous line for a column of the same table?

Hello

I have a table where there are 3 rows and say 2 columns only, as below

Col1               | Col2
--------------------- |----------------------------------------

first_flag |  100

second_flag |  104

third_flag |  110

Now, using sql, which accepts a parameter col1, how do I get the bottom o/p

say that the entry is second_flag,

output must be

second_flag, 104, 4 (4 being the difference between 104 and 100)

If I give the entry like third_flag, the output should be

third_flag, 110, 6 (6 is the difference between 110 and 104)

Any help?

Hello

Another way is to use the analytic LAG function:

WITH got_diff AS

(

SELECT col1, col2

, col2 - LAG (col2) over (ORDER BY col1) AS diff

OF mydata

)

SELECT *.

OF got_diff

WHERE col1 =: flag_wanted

;

This assumes that the lines are in alphabetical order by col1.  If the order is something else, then use it in the ORDER BY clause analytical.

Tags: Database

Similar Questions

  • How to get the underlying tables

    Hi all

    EBS R12.2

    How can I get the underlying tables of the following form?

    Capture.PNG

    Thank you very much

    Jen

    Hello

    Go to help-> review-> properties-> point.

    That's how you get the base table (FND_USER_RESP_GROUPS_INDIRECT):

    Kind regards

    Bashar

  • How to get the same look as the flash for borders?

    Hi I have selected the circle and the circle filled with certain colors. now, I want to have the border around the circle so I saelected STROKE in the Edit menu and applied with a pixel. How ever it gives a strong appearance in flash. in photoshop, the border looks like dissolved and transparent. is there a way to get the same look as the flash?

    I would recommend using shape layers (starting with the Ellipse tool) instead of a selection.

    Cs6 on shape layers can have stroke (located in the Options bar).

  • How to get the same day of a month each year in the DB (update a flag)

    Hello

    I'm trying to make a update for a table of flag request in our database that contains the dates and the Pavilion columns. Currently the system have dates for the next ten years. The flags are updated with the values 0 or 1, if a particular date falls under the criteria required.

    I need to update the column flag for the same day of the month of each year. for example, 2nd Sunday of October. The value must be updated in all the years in the table. Currently I use the following query to update of the current year.

    UPDATE FILTERCALENDAR SET YEAR_WINDOW = 1 WHERE c_date = NEXT_DAY (TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1) * 7;

    and for the next year as

    UPDATE FILTERCALENDAR SET YEAR_WINDOW = 1 WHERE c_date = add_months (NEXT_DAY (TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1) * 7, + 12)-1;

    This isn't a great way to do it because he does not take care of leap years, and it does not scan and update values across the table for all the years correctly.

    Can someone help me fix this please.

    Welcome to the forum!

    Whenever you provide post your Oracle version 4-digit (result of SELECT * FROM V$ VERSION)
    >
    and for the next year as

    UPDATE FILTERCALENDAR SET YEAR_WINDOW = 1 WHERE c_date = add_months (NEXT_DAY (TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1) * 7, + 12)-1;
    >
    Why do you use "2013" in the TO_DATE for the year next rather than use simply '2014 '?

    You said it works
    >
    UPDATE FILTERCALENDAR SET YEAR_WINDOW = 1 WHERE c_date = NEXT_DAY (TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1) * 7;
    >
    Just interview the years from your table (list of the separate years) and use the query above on them.

    SELECT DISTINCT TO_CHAR(c_date, 'yyyy') FROM FILTERCALENDAR
    

    Or use this predicate

    WHERE c_date = next_day(last_day(add_months (c_date, -1)), 'SUNDAY') + 7
       AND TO_CHAR(c_date, 'mm') = '10'
    

    1 TO_CHAR ensures that the line has a month to October.
    2 ADD_MONTHS goes to Sept. 1.
    3 LAST_DAY going until the last day of September.
    4 NEXT_DAY goes to the first Sunday in October
    5 + 7 is going to the second Sunday in October

  • How to get the same functionality for string as java in oracle 10g

    Example:

    In java, if I use
    -> > >
    String.format ("% 03d", 11) then he will give me the result 011
    String.format ("% 03d", 1111) then he will give me the result 1111

    I need also same result in Oracle for a stored procedure. I used to_char() and lpad() function but could not get the desirable.

    I'm new on this. Please forgive for this silly question and help me.

    Or with the prefix "FM", which makes the FILLING for us:

    to_char(col1, 'fm9999099')
    
  • How to get the same result on different characterset?

    Hello experts,

    I use

    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    "CORE 11.2.0.3.0 Production"
    TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    
    

    Needing a result even on my example.

    SELECT ASCII('ˆ') -- when characterset is -NLS_CHARACTERSET WE8MSWIN1252
    FROM DUAL;
    --result 136
    
    

    SELECT ASCII('ˆ') -- when characterset is -NLS_CHARACTERSET AL32UTF8
    FROM DUAL;
    --result 52102 but need 136
    
    

    I need same result.

    Thanks for your time...

    EDITED RESULT.

    Ask2Learn

    You test something that you call "encrypted" data, which are not at all encryption.

    For example speaking of letter t.

    The CHR (ASCII('t') + 20) operation is pretty useless. You try to find the character that has the code binary and longer than 20 that the letter 't'. This can work with single-byte as WE8MSWIN1252 character sets, but it does not work with variable width as AL32UTF8 character sets. The letter 't' a code 0 x 74 in WE8MSWIN1252 and AL32UTF8. If you add 20 (decimal), you get 0 x 88. Byte 0 x 88 is a valid code in the WE8MSWIN1252, but is not a valid code in AL32UTF8. Bytes in this range may bytes of continuation in AL32UTF8, i.e. a second, third or the fourth byte of a multi-byte sequence.

    The "circumflex accent" character code 0 x 88 (in WE8MSWIN1252) has the code of two bytes 0xCB 0 x 86 in AL32UTF8.

    So, why not take a look at DBMS_CRYPTO integrated


    Hope this helps


    Hamid

  • How to get the a table check constraint.

    I don't see the function to get forced check.
    I try the table.getCheckConstraints () function
    but I return nothing.

    Hello

    table.getCheckConstraints () will return to check the constraints defined at the Table level in the Data Modeler.

    You can also call column.getCheck (). This will return a check constraint defined on a column object in the Data Modeler.

    David

  • Could not get the same font in the swf file

    Hello

    I created a swf files in which the text was written using a particular font. When I run the swf files on other computers that do not have this font, the text gets displayed in different characters.

    How to get the same font in other computers also without having to install the font.

    I tried embedding fonts in the fla file. But I made the mistake to a place. Could someone help me understand?

    Thank you!

    Hello

    Finally, I found the reason for the display of incorrect fonts on different computers. It is the font settings.

    In the font settings, Anti alias has been defined as use device fonts. That's why he was choosing fonts of device on which the machine is not. Now, I changed it to anti-alias for animation. I was not even embed all fonts. It works perfectly.

    I do not change even from static to dynamic text text. Just changed the parameters of smoothing. Is this right? Could you tell me whether he set the anti-alias for animation or anti-alias for readability, I see no big difference between the two but?

    Thanks for your great support in due course.

    Thank you.

  • Chart WPF: How to get the limits of PlotArea and axes

    I can't find explicit methods to get limits of PlotArea and axes.

    Please let me know workarounds if they are available. Actually a post explains how to get the PlotArea limits using RangeCursor. Are there alternative means for shafts?

    The photo below shows what I did in WinForms with the methods GetBounds and HitTest. I would like to draw the ornaments on the chart in WPF.

    I have attached a code example of this look ornaments around the plot area and the scales.

    Note that this relies on implementation details of the current version of WPF controls for the ornaments of the scale, as it was more effective than gradually points to test in the graph using the GetScaleAt method. We have intentionally left much of the underlying primitive types with a minimum documentation, like us they have changed in the past and may change in the future. Although these exact members can be removed in a future release, we do not expect to provide an equivalent function and stabilize the primitive API over time.

  • How to get the current location in the event thread?

    Hello!

    Can U pls tell me how to get the location where the thread object, it is in method() execution of MenuItem. PLS, tell me-

    I also used the different thread for the getLocation() method. But I do not have the coords of geo location...

    PLS, suggest me-

    My code is as below:

        private MenuItem getGeoCodes=new MenuItem("Current Coords",100,1){
    
                                 public void run(){
                                     double[] coords=getLocationCoords();
                                     this.wait(12000);
                                     System.out.println("Latitude :"+coords[0]+" "+"Longitude:"+coords[1]);
                                 }
    
                     };
    
        private double[] getLocationCoords(){
            Criteria criteria = new Criteria();
            criteria.setHorizontalAccuracy(500);
            criteria.setVerticalAccuracy(500);
            LocationProvider locationProvider = LocationProvider.getInstance(criteria);
            Location location=null;
            new Thread(){
               public void run(){
                       locationProvider.getLocation(60);
               }
            }
            QualifiedCoordinates qualifiedCoordinates=location.getQualifiedCoordinates();
            double[] coords=new double[]{qualifiedCoordinates.getLatitude(),qualifiedCoordinates.getLongitude()}   ;
             return coords;
        }
    

    But I myself NullPointerException. Coordinates get successfully, if we run the location capability in different function, rather than the event thread.

    Please help me-

    In my opinion, which may be too complicate things a bit. I think he's trying to do is register a LocationListener with his object of LocationProvider. Callback methods, send a message to the UI event thread as follows (no need to spawn threads):

    UiApplication.getUiApplication().invokeLater( new Runnable() {
        public void run()
        {
            // This code will execute on the event thread
        }
    });
    

    EDIT: If your interval is short, you can consider implementing this executable as a class and store an instance in the front.

  • How to get the frame number current timeline using jsx?

    How to get the frame number current timeline using jsx?

    Thanks for the link!

    Clarification: I was looking for the current image on the timeline of the video. OP he mentions that he had found how to get that so I searched a bit more and found this thread: Re: can I inpoint in read/write and out-point of the clips in a group of video with scripts? They have the following functions, I have not tried yet, but it seems like it should work.

    function getCurrentFrame() {}

    try {}

    Var ref = new ActionReference();

    ref.putProperty (charIDToTypeID ('Rprp'), stringIDToTypeID ('currentFrame'));

    ref.putClass (stringIDToTypeID ('timeline'));

    var / / desc = new ActionDescriptor();

    desc.putReference (charIDToTypeID ('null'), ref);

    var TC = executeAction (charIDToTypeID ('getd'), desc, DialogModes.NO);

    Return TC.getInteger (stringIDToTypeID ('currentFrame'));

    } catch (e) {return null ;}

    };

  • How to get the 'DAY' based on the territory of current account held a number between

    Hi all

    Looks like I'm at the end of my intelligence here but how to get the 'DAY' based on the territory of current account with a number between 1 and 7? Oracle has functions to extract the day of the week, but I can't find the other way around.
    SQL> select * from v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for Linux: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    
    SQL> alter session set nls_territory=AMERICA;
    
    Session altered.
    
    SQL> select to_char (sysdate, 'D') from dual;
    
    T
    -
    3
    
    SQL> alter session set nls_territory=GERMANY;
    
    Session altered.
    
    SQL> select to_char (sysdate, 'D') from dual;
    
    T
    -
    2
    I need a way to know that the number '3' on the database with NLS_TERRITORY = AMERICA means a 'Tuesday' or the number '2' on a database with NLS_TERRITORY = GERMANY means "Tuesday" as well.

    Hope I am clear enough.

    And wish you all a happy new year :)

    Kind regards
    Smail

    Use the format "IW" to get the date of Monday and the format "DAY" to get the "first day of the week. Then compare dates to see if they are identical.

    ALTER SESSION SET NLS_TERRITORY = 'AMERICA';
    
    SELECT TRUNC(SYSDATE-LEVEL, 'IW') "Monday",
    TRUNC(SYSDATE-LEVEL, 'DAY') "NLS First day of week",
    MOD(TRUNC(SYSDATE-LEVEL, 'IW') - TRUNC(SYSDATE-LEVEL, 'DAY') + 7, 7) "1 if day 1 = SUN, 0 if MON"
    FROM DUAL CONNECT BY LEVEL <= 7;
    
    Monday    NLS First day of week 1 if day 1 = SUN, 0 if MON
    --------- --------------------- --------------------------
    31-DEC-12 30-DEC-12                                      1
    24-DEC-12 30-DEC-12                                      1
    24-DEC-12 23-DEC-12                                      1
    24-DEC-12 23-DEC-12                                      1
    24-DEC-12 23-DEC-12                                      1
    24-DEC-12 23-DEC-12                                      1
    24-DEC-12 23-DEC-12                                      1
    
    alter session set nls_territory = 'FRANCE';
    
    SELECT TRUNC(SYSDATE-LEVEL, 'IW') "Monday",
    TRUNC(SYSDATE-LEVEL, 'DAY') "NLS First day of week",
    MOD(TRUNC(SYSDATE-LEVEL, 'IW') - TRUNC(SYSDATE-LEVEL, 'DAY') + 7, 7) "1 if day 1 = SUN, 0 if MON"
    FROM DUAL CONNECT BY LEVEL <= 7;
    
    Monday   NLS First day of week 1 if day 1 = SUN, 0 if MON
    -------- --------------------- --------------------------
    31/12/12 31/12/12                                       0
    24/12/12 24/12/12                                       0
    24/12/12 24/12/12                                       0
    24/12/12 24/12/12                                       0
    24/12/12 24/12/12                                       0
    24/12/12 24/12/12                                       0
    24/12/12 24/12/12                                       0
    

    Or it could be simpler:

    ALTER SESSION SET NLS_TERRITORY = 'AMERICA';
    
    WITH DATA AS (SELECT LEVEL INPUT_DAY FROM DUAL CONNECT BY LEVEL <= 7)
    SELECT INPUT_DAY,
    TO_CHAR(TRUNC(SYSDATE, 'Day')+INPUT_DAY-1, 'DAY') "Day label"
    from data;
    
    INPUT_DAY Day label
    --------- ------------------------------------
            1 SUNDAY
            2 MONDAY
            3 TUESDAY
            4 WEDNESDAY
            5 THURSDAY
            6 FRIDAY
            7 SATURDAY
    
    alter session set nls_territory = 'FRANCE';
    
    WITH DATA AS (SELECT LEVEL INPUT_DAY FROM DUAL CONNECT BY LEVEL <= 7)
    SELECT INPUT_DAY,
    TO_CHAR(TRUNC(SYSDATE, 'Day')+INPUT_DAY-1, 'DAY') "Day label"
    from data;
    
    INPUT_DAY Day label
    --------- ------------------------------------
            1 MONDAY
            2 TUESDAY
            3 WEDNESDAY
            4 THURSDAY
            5 FRIDAY
            6 SATURDAY
            7 SUNDAY
    
  • How to get the current position from the point of view

    can I know how to get the current position of the view?

    Edited by: anIdiot July 27, 2011 22:01

    1 - get belvedere of the universe:

    u = new SimpleUniverse (canvas3D);
    ViewPlat = u.getViewingPlatform (); view of the universe

    definition viewplat: ViewingPlatform ViewPlat;

    2 - get look a transform of the platform in an existing Transform3D

    ViewPlat.getViewPlatformTransform () .getTransform (t3d).

    3 - Look at the trandform: t3d.get (Quater1, vector1); orientation object Get and coords

    Kind regards.
    JFP

  • How to get the difference in dates in days

    Hi friends,

    How to get the date difference between two dates exactly

    date2-date1 days exactly... shouyld rounded to the nearest value of...

    and one entire display i mean positive integer
    Select round ((sysdate) - to_date (date_start)), date_start days of per_periods_of_service

    This gives negative also result

    Hello

    776317 wrote:
    Hi friends,

    How to get the date difference between two dates exactly

    date2-date1 days exactly... shouyld rounded to the nearest value of...

    Date1 - date2 is the exact number of days is after date2 date1. (It is as accurate as possible, given that the DATEs do not have fractions of a second).

    and one entire display i mean positive integer
    Select round ((sysdate) - to_date (date_start)), date_start days of per_periods_of_service

    You want to probably get the exact number of days first, then ROUND this number:

    SELECT  ROUND (SYSDATE - TO_DATE (date_start, ...))   AS days
    FROM    per_periods_of_service; 
    

    Always pass arguments at least 2 to TO_DATE:
    (1) the string to be converted, and
    (2) a saying string how (1) is formatted

    This gives negative also result

    Right; If date1 is before date2 then date1 - date2 returns a negative number.
    If you want to never get a negative value, use ABS (date2 - date1). If it returns 4, then you know that one of the DATEs was 4 days before the other, but you won't know who was earlier.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

  • How to get the width and height of Flex Mobile view?

    Hello

    The following instructions can get the width and height of the current Flex app:

    var request: UIComponent = FlexGlobals.topLevelApplication as UIComponent;

    trace (application. Width);

    trace (application. Height);

    But I don't know how to get the width and height of mobile display Flex current (i.e. the content size excludes bar action and the Navigation bar). Why the "this.width" always returns 0?

    Thank you!

    Looks like you're running in this bug: https://bugs.adobe.com/jira/browse/SDK-30070

Maybe you are looking for

  • scrollspeed Firefox 17 esr

    So, I use Firefox for a while and I've always changed the "mousewheel.withnokey.numlines" in to increase my scrollspeed of calm. I love that she's 18 or more. It worked like a charm so far when I tried swapping FF10 ESR ESR FF17. I disabled the smoot

  • technical documentation of 5830t motherboard needed

    I am looking for the technical manual of the motherboard because I can't believe the allowed max ram is 8 GB. If you can provide it, it would be much appreciated. Thank you Maria

  • AIO7520: HP7520 photo Posiflex

    Hello I have a problem with printing photo and HP Photosmart 7520: printing on 4 "x 6" paper (from photo tray) are out of alignment: the printed image is not parallel to the leaf. " It seems that sheet is loaded correctly (no), but printing is turn!

  • Phone smart BlackBerry Passport not taken in charge by the Blackberry Desktop software

    I loaded the software of the Passport, and he gave the above message. "The BlackBerry is running on OS 10.  BlackBerry desktop software does not support the Blackberry 10 operating system". Kindly advise me?

  • ViewMail, no response from the server

    Hello I have a user that does not stop a server on its viewmail message response.  I uninstalled Viewmail and reinstalled, who worked for a day.  The next day, the same message that has happened. ViewMail Version: 9.0.0.2 Variant of connecting the un