How to subtract the current value of the next value (row) in the same column

Hello

I am struggling to write a SQL query that can do something like, as shown in the example.

Suppose I have a value with values as a column

VALUE
---------------
21138672941
21266223360
21375446692
21464626060
21546520653
21616643777
21689565041
21781762699
21882541342
21983644803
22086697638

My requirement is to write a query to subract 1st row of second, second in the third, third in the fourth and so on.
The output should be 127550419, 109223332 and so on.

Is this possible with a request? Please give me the code pl/sql query if possible.

Concerning
Smail

No problem. Should be as simple as taking my query and replace 'data' a 'test', but you can change the order of Analytics at snap_id

select value
       , lag(value) over (order by snap_id) prev_value
       , value - lag(value) over (order by value) diff
   from test;

Give it a try

Tags: Database

Similar Questions

  • How to find the same column name in different tables in the same schema

    Hello

    I find the 'ename' column name in different tables in the same schema.

    Thank you
    Nr

    Hello

    Try this query

    Select column_name, table_name from user_tab_columns where column_name = 'ENAME ';

    Award points and end the debate, if your question is answered or mark if she was...

    Kind regards

    Lacouture.

  • How to subtract the DATE CURRENT SYSTEM and tire of Siebel

    Hi Experts,

    How to subtract the date of DAY and Date, which came in Siebel?

    Example:
    The DAY - Date records in Siebel

    Current date = 25/11/2012
    Registration date in Siebel = 20/11/2012

    Technically the answers I want will be 5.
    How can I do this? My idea is to put a phrase in the MDB layer, but I want to just get your ideas:

    Current_Date - "Oracle Data Warehouse. "'"' Catalogue'."" """dbo"."" TABLE_NAME ". "' COLUMN_NAME '.


    Thank you!

    Hello

    You can use the available in OBIEE timestampdiff function to get the difference between two dates. This is one of the blogs that can help with the syntax.

    http://Shahin-OBIEE.blogspot.in/2012/04/various-calculations-for-date_16.html

    You can also google timestampdiff function for details on usage and syntax.

    Thank you

  • By subtracting the values in the same column?

    Hello

    How can I subtract two values in the column of the table. EG - there is a table with two columns with date and cumulative turnover.

    Date Total_sales
    ===== =======
    February 23, 68
    24 feb-122
    25 feb-150
    26-Feb-200
    27 feb-223

    I need to know about the date that sales have been maximum. As we can see on 24 - Feb, sales were 54. We do this by subtracting 122-68.
    How can subtract us values in the same column?

    Thank you

    Take a look at the lag() of analytic SQL function which should give you what you need.

    See you soon,.
    Harry

  • How to map the same tag of the element with a different value in BI Publisher rtf model.

    Hello

    I have an xml file with the same name in the < tag > element and I do not know how to associate the same < tag > element to different string in the document rtf template attribute.

    For example: "' Eswitch <number > is repeated in this xml file, when I am mapping this element to the document rtf with a different string, I have same value 'D00002 ' . I should get values D00002 and DMR00002.

    < document >

    < TitleBlock >

    < number > D00002 < / number >

    < itemType > Document < / itemType >

    < lifecyclePhase > preliminary < / lifecyclePhase >

    < description > gtedgg < / description >

    < shippableItem > n < / shippableItem > < / cartridge > < / Document >

    < DMR >

    < TitleBlock >

    < number > DMR00002 < / number >

    < itemType > DMR < / itemType >

    < lifecyclePhase > preliminary < / lifecyclePhase >

    test nomenclature model bom1 < description > < / description >

    < POS > < value > Test < / value > < / POS >

    < shippableItem > n < / shippableItem > < / cartridge > < / DMR >

    < / AgileData >

    I followed steps below for map document model rtf with the same tag xml with a different value.

    1. install Office word 2013.

    2 BI Publisher for desktop software installed. It will add a BI Publisher plugin to the word document.

    3. with the help of desktop publisher BI, created a model of document rtf file.

    4 imported the document rtf template example xml file.

    The data is loaded successfully.

    5 tires model rtf field symbol to map the tags to xml to rtf document attributes element.

    7 saved the document in PDF format.


    Thank you

    Please mark it correct so that it is useful for others to find the solution to a similar request.

  • How to display the database column value in a component of choice selected?

    Hello everyone;

    I use Jdeveloper 11.1.1.4 and right now I have the .jspx UI page that includes < af:selectonechoice / > components and according to the requirment I have to fill one of the column in the table in this drop-down list.

    can someone tell me how to fill the database column value in this drop-down list. I know I need to create the VO for the same thing, but I'm new to this technology. Then please suggest.

    Thanks in advance.,

    This will help u

    https://blogs.Oracle.com/prajkumar/entry/create_lov_in_adf_application

    How to create LOV in ADF 11 g | Techartifact

    Oracle Fusion Middleware Technologies: 11G: how to create a list of Values (LOV)?

    http://www.baigzeeshan.com/2010/03/creating-lov-in-ADF-application.html

    http://husaindalal.blogspot.de/2010/05/How-to-default-lov-with-its-first-value.html

  • an alphabet by typing in a cell gives drop down suggestions from previous hits on the same column. But how the drop down to choose the suggestions of the other columns and other sheets.

    an alphabet by typing in a cell gives drop down suggestions from previous hits on the same column. But how the drop down to choose the suggestions of the other columns and other sheets.

    Hi mdsavol,

    Your observations are accurate. The 'suggestions' are previous entries in the same column that correspond to what has been entered so far in the active cell. The only direct user control is to activate the function turn on or off in numbers preferences > general.

    There are other ways to include or exclude items of suggestions:

    • To remove typos in the suggestions list, the user must correct the typos in the cell above the active cell. If they are more in the list, they won't be presented as suggestions.
    • To include selections added to the list, the user must enter these suggestions in the individual cells above the active cell and column where they are wanted as suggestions.

    There was a request here a while there is a list of suggestion 'live' similar to those of some websites, which offers a descending list of possible entries as a type in an input box.

    The only way I see to reach a solution similar to what you have asked is to use as many lines at the top of the non-en-tete of the table section to list the items likely to repeat in your table, and then hide the lines. You'll need a list for each column where you want to use this feature with a list previously planted. Existing items will then require a likely hit up to three, then a click to choose from a list small enough to enter a value into a cell. News he will need to enter in full the first time, but after that it will be put on the list and answer the same thing as the terms preseeded.

    While your setting upward (or decide not to do), consider going on the menu of number (in numbers), choosing to provide feedback from numbers and writing a feature in Apple request. Describe what you want. Explain how he could help the average user numbers, and then hope for the best.

    Kind regards

    Barry

  • Multiple values for the same column in the columns of diffétent in the same row?

    Hi all
    I wonder how you can display different values for the same column in different columns on the same line. For example, using a CASE statement, I can:

    CASE WHEN CODE IN ('1 ', ' 3') THEN COUNT (ID) AS 'Y '.
    CASE WHEN CODE NOT IN ('1 ', am') THEN COUNT (ID) AS "N".

    Yes, that will produce two columns but will produce null values to empty and also two separate registers.


    Any ideas?

    Thank you

    Are you sure that this code works for you?

    Select ID
             ,CASE WHEN MODE_CODE IN ('1', '3') THEN COUNT( No) END as "Fulltime"
             ,CASE WHEN MODE_CODE NOT IN ('1', '3') THEN COUNT( No ) END  as "Other"
    From table
    group by ID
    

    I guess the code above fails because MODE_CODE is not in your group by?

    My suggestion would be to put the CASE in the COUNT:

    Select ID
             ,COUNT(CASE WHEN MODE_CODE IN ('1', '3') THEN No END) as "Fulltime"
             ,COUNT(CASE WHEN MODE_CODE NOT IN ('1', '3') THEN No END)  as "Other"
    From table
    group by ID
    

    CASE expressions return no. when the respective conditions are true and NULL otherwise.
    COUNTY will have non-null values.

  • By comparing the values in the same column

    Hello

    I have a requirement to do the following:

    The guest of the dashboard has two drop downs as 'Acct number 1' and others as 'Acct number 2 ". Both are the same column from the database. When two different values are chosen from the prompt, it should produce a report with the following 5 colomns, 'ACCT1', 'SALES AMOUNT ACCT1', "ACCT2", "SALES AMOUNT ACCT2", "DIFFERENCE".

    I tried to use a variable of presentation in the command prompt and it fills my column pther having the same value I have input for the first prompt.

    How can I do this? Thanks for your time and your help.

    Hello

    You can try it at the level of the report.

    * Ensure that you have set your guests with different effects. Suppose that the two PVs are acc1 and acc2.
    * Report, add below filter
    Account number is equal to @{acc1} {defualtvalue}
    OR
    Account number is equal to @{acc2} {defualtvalue}
    This will filter the report by the two account numbers.
    * Now apply below in your fx of all columns.

    "ACCT1: ' @{acc1} {defualtvalue}"
    ACCT1 SALES AMOUNT: FILTER (with the HELP of SalesCol (AccountNumber = ' @{acc1} {defualtvalue}'))
    "ACCT2: ' @{acc2} {defualtvalue}"
    ACCT2 SALES AMOUNT: FILTER (with the HELP of SalesCol (AccountNumber = ' @{acc2} {defualtvalue}'))
    DIFFERENCE: FILTER (with the HELP of SalesCol (AccountNumber = ' @{acc1} {defualtvalue}'))-FILTER (with the HELP of SalesCol (AccountNumber = ' @{acc2} {defualtvalue}'))

    Thank you

  • How to use the same services-config for servers the and remote.

    My flex project works very well using the bottom but when I download my flash on the server I do not work, all the files and related paths are the same execpt remote is a linux server.

    <? XML version = "1.0" encoding = "UTF-8"? >
    <>services-config
    < services >
    < id = 'amfphp-flashremoting-service' service
    Class = "Flex.Messaging.services.RemotingService"
    messageTypes = "flex.messaging.messages.RemotingMessage' >"

    < destination id = "amfphp" >
    <>channels
    < Ref channel = "my-amfphp" / >
    < / channels >
    Properties of <>
    < source > * < / source >
    < / properties >
    < / destination >
    < / service >
    < / services >
    <>channels
    < channel-definition id = "my-amfphp" class = "mx.messaging.channels.AMFChannel" >
    " < endpoint uri = ' http://localhost/domainn.org/AMFPHP/gateway.php "class="flex.messaging.endpoints.AMFEndpoint"/ > "
    < / channel-definition >
    < / channels >
    < / services-config >

    I think the problem is the line


    " < endpoint uri = ' http://localhost/domainn.org/AMFPHP/gateway.php "class="flex.messaging.endpoints.AMFEndpoint"/ > "

    but I don't know how to use the same services-config for servers the and remote.

    I'll back up a bit.

    Breakpoint URLS are defined as follows in the services - config.xml:

    https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure

    The meaning of each of the tokens is clearer when we see them as part of a complete url. If your context root is set to http://localhost , then I have no idea how your application runs in any environment.

    If you leave the server.name and server.port chips in your configuration file, then they will be replaced when executing according to the location from which your application is served. However, the context.root token is replaced at the time of the compilation based on the value that you specify in Flex Builder or when calling mxmlc.

    In order to reuse your file services - config.xml, you must use the same context-root on your development environment and to your deployment environment.

  • I made my largest site and how can keep the same size for all other sites?

    I did the 2 larger site and how to keep the same size for all pages when I re - open the web browser?

    You can use an extension to set a page zoom and the size of the default font on the web pages.

  • How to put the 2nd column 1st column in excel

    Hello

    I have a question how to set the 2nd column 1st column in excel. Thank you.

    Why the 1 iteration for loops?

    Why two Index tables?  He's just trying to solve the problem created by the loops For on the original 1 d arrays.

    Two of these things create 2D tables which are what complicates things and can be eliminated.

    You can take your 2 1 d tables, use build table and right-click to set 'concatenate the inputs.

    If you have a 2D array, you can use table remodel to make a 1 column of the table of N line 2D.

  • How to read the two columns of data from the Port series

    Hello

    I'm reading two columns of data from the serial port.

    Example:

    52439 52430

    52440 52437

    52209 52214

    51065 51070

    52206 52390

    I use the serial of Visa service and I can read the first column of data from the serial port, but I can't understand how to read the second column.

    I want to both sets of chart data.

    I enclose my VI.

    Thank you for your help.

    The analysis of string function takes a "Format string" on top (with the right button of the function and choose Help, which explains all the entries).  In particular, you can say 'Give me two numbers separated by a tab' and the output will be two numbers (whole or floating, depending on the chosen format).  In particular, %d\t%d specifies a decimal integer, , whole decimal.

  • Columns of folder: by default, how can return the first column 'Name' without having to move it manually every time?

    Something's happened awhile and when I create a folder which appears the first column is the column 'Date modified '. By default, how can return the first column 'Name' without having to move it manually every time?

    Hello

    I suggest you to visit these links and check if it helps:

    http://Windows.Microsoft.com/en-us/Windows-Vista/working-with-files-and-folders#section_4

    http://Windows.Microsoft.com/en-us/Windows-Vista/folders-frequently-asked-questions

    It will be useful.

  • How to display the comments column in Windows Media Player 12?

    WMP12 - how to display the comments column?

    I want to see the Cooments ColonneB in my WMP ads, but it is not giving me the option.

    Hello

    1. What do you mean exactly by the column comments?
    2. are you referring to in Windows Media Player?

    If you want to change the information contained in the Windows Media Player, you can follow the steps in this article.

    http://Windows.Microsoft.com/en-us/Windows7/add-or-edit-media-information-in-Windows-Media-Player

  • How to add the new column in existing table to our desired location?

    How to add the new column in existing table to our desired location?

    For example, I have to add the new column 'course' before the salary column in the emp table.

    I think the best way is to add the column at the end of the table and create a new view with the order of the columns...

    Another option...

    places the data into a temporary table and recreate the table with the correct order of the columns, and then insert data to the table from the temporary table

    Refer

    Add column (from table) in the desired position

    Example:

    CREATE TABLE temp_my_user LIKE)

    SELECT * FROM password);

    DROP TABLE password;

    (Password) CREATE TABLE

    userID NUMBER

    , first name VARCAHR2 (25)

    , middleInitial VARCHAR2 (1)

    (, name VARCHAR2 (25));

    INSERT INTO password (userID, firstName, lastName)

    (SELECT username

    first name

    lastName

    OF temp_my_user);

    DROP TABLE temp_user;

Maybe you are looking for

  • Want to turn on or off an exit and turn off every minute

    Hi all What is the best way to configure a loop to output is enabled/disabled/disable every minute? Thank you.

  • bar code with normal text

    Hi all In my application, I want to generate a bar code and printing as well as write normal text underneath. I tried to do, but my vi all converted code bar. I want that the "part number, revision, vender code, string to date and serial number" to p

  • How to add sound to the General error handler

    I'm looking for an easy way to create a sound signal (beep or something) when the General error handler displays an error message.  Someone at - it suggestions?

  • Clip + downloads audiobook of WinMed but do not play book.

    Copy a Clip +, 4 GB. Downloaded a book from Audible.com in the WinMed library. Book downloaded from WinMed in Clip +. Book shows title in audio books CLIP + bit will not play. Simple answers or ways to go about this. Want to drop and drag if possible

  • How can I fix code backup failed: 0 x 800700002

    Original title: I have two computers both with separate hard drive backup. Since the end of last year I received the notification of backup failure due to the same file missing 0 x 800700002. How can I retrieve this file? A computer is a Dell laptop,