subtracting the two rows in the same column

Hello
I have the following table with about 6000 lines of different year_month, but I compare and subtract v
Contribution of the Organization Year_month
Kano 200000 JAN-2011
KADUNA 300000 JAN-2011
ABUJA 400000 JAN-2011
Kano 300000 FEB-2011
KADUNA 200000 FEB-2011
ABUJA 600000 FEB 2012
I want to choose a year_month runtime to subtract the contribution of the first contribution of the second year_month year_month and give me the result, as shown in the following table
Difference of JAN - FEB 2011 - 2011 organization
Kano 200000 300000-100000
300000 200000 100000 KADUNA
ABUJA 400000 200000 600000
Here is my code back will too

create or replace function "GET_MONTHLY_VALUE".
(q_name in VARCHAR2,
hmoCode in VARCHAR2)
return VARCHAR2
is
number of C1;
Start
Select NHIS_CONTRIBUTION in c1 of CONTRIBUTION_MGT where upper (YEAR_MONTH) = upper (q_name) and upper (ORGANIZATION) = upper (hmoCode);

return to c1;
exception when NO_DATA_FOUND THEN
Returns a null value.
end;

-a call to the function above:

create or replace function process_cont_monthly return varchar

is
Cursor cont_cursor is select ORGANIZATION of CONTRIBUTION_MGT;
Start
for
cont_rec loop cont_cursor
First, select GET_MONTHLY_VALUE(:p26_month,cont_rec.ORGANIZATION) GET_MONTHLY_VALUE(:p26_month2,cont_rec.ORGANIZATION) second,
ABS (GET_MONTHLY_VALUE (:p26_month,cont_rec.ORGANIZATION)-GET_MONTHLY_VALUE(:p26_month2,cont_rec.ORGANIZATION)) difference
of CONTRIBUTION_MGT;

end loop;
commit;
end;
I got totally confused and do not know what to do next
Any help and the best guide is appreciated

Analytics can also be used (assuming that you store dates as dates, ORDER BY working properly)

create table t(org varchar2(10),mon date, cont number);
insert into t(org,mon,cont) values ('Kano',to_date('201101','YYYYMM'),200000);
insert into t(org,mon,cont) values ('KADUNA',to_date('201101','YYYYMM'),300000);
insert into t(org,mon,cont) values ('Kano',to_date('201102','YYYYMM'),300000);
insert into t(org,mon,cont) values ('KADUNA',to_date('201102','YYYYMM'),200000);
commit;

select * from t;
ORG        MON                    CONT
---------- ---------------------- ----
Kano       01-JAN-2011 00:00:00   200000
KADUNA     01-JAN-2011 00:00:00   300000
Kano       01-FEB-2011 00:00:00   300000
KADUNA     01-FEB-2011 00:00:00   200000 

select org,cont1 start_month,cont2 end_month,cont1-cont2 difference
  from (
        select org,mon,cont cont1,
               lead(cont) over (partition by org order by mon) as cont2
        from t
        where  mon in (to_date('201101','YYYYMM'),to_date('201102','YYYYMM'))
        )
where cont2 is not null;

ORG        START_MONTH END_MONTH DIFFERENCE
---------- ----------- --------- ----------
KADUNA          300000    200000     100000
Kano            200000    300000    -100000 

Tags: Database

Similar Questions

  • 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

  • A target table is in charge of two different sources but the same columns, but a source is one database and another in a flat file.

    We all hope you are doing well.

    I have a business problem to implement in ODI 11 G. It's here. I'm trying to load a target table from two sources that have the same column names. But a source is to the file format and the other is in the Oracle database.

    That's what I think I'll create two mappings in the same interface by using the Union between the sources. But I don't know how the interface would connect to different logical architecture to connect to two different sources.

    Thank you

    SM

    You are on the right track, all in a single interface. Follow these steps

    (1) pull model of your data in the designer of the source file and your table model target to the target pane.

    (2) all relevant columns map

    (3) in the source designer to create a new dataset and choose as the UNION join type (this will create a separate tab in the source designer pane)

    (4) select the new dataset tab in the source designer pane and pull your source oracle table data model in the designer of the source. All columns that are relevant to the target card

    (5) make sure that your staging location is set to a relational technology i.e. in this case the target would be an ideal candidate because it is where the ODI will organize the data from source two files and oracle and perform the UNION before loading to the target

    If you want to watch some pretty screenshots showing the steps above, take a look at http://odiexperts.com/11g-oracle-data-integrator-part-611g-union-minus-intersect/

  • 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.

  • Two or more SRID in the same column?

    Hello, I am working with Oracle Spatial, and I have a problem with the SRID.

    I have a column in a table with the SDO_GEOMETRY type and I need to create a Spatial Index to use. But to create a Spatial Index first, I need to insert metadata into the table incluied SRID: for example

    Insert in user_sdo_geom_metadata (table_name, column_name, srid, diminfo) values ('Spatial_Test', 'GEOMETRIA', 8307, SDO_DIM_ARRAY (SDO_DIM_ELEMENT('LONGITUDE',-180,180,0.5), SDO_DIM_ELEMENT ('LATITUDE',-90, 90, 0.5)));

    But I need to work with more than one SRID in this column. Is there anyway to have two or more SRID in the same column? How? and if I insert them, can they give any problem?

    Thank you very much.

    Good bye.

    ZeyKa,

    . . . . You can transform and store all your geometries in SRID 8307 and then turn to their original SRID when you SELECT them.

    -- "Example: Transform geometry from  to SRID 8307 for storage"
    -- "NOTE: Replace  and  with your values"
    INSERT INTO MyTable (ID, geometry,RenderSRID) VALUES (1, SDO_CS.TRANSFORM(,8307), );
    
    -- "Example: Transform stored geometry back to its "
    SELECT SDO_CS.TRANSFORM(geometry,RenderSRID) FROM MyTable WHERE ID = 1;
    

    Kind regards
    Noel

  • Two guests on the same column

    Hi Experts,

    I'm defining two different guests (and associate them with the two variables of different presentation) on the same column. However, when I view the 2 guests on the same dashboard page, whenever I select a value for the first prompt, the same value is automatically selected for the second line.

    Is this a normal behavior? How to capture the two distinct values?

    Thank you
    Guillaume

    Hi William,.

    I think I forgot something.

    You must do the following steps:

    (1) add the column to the dashboard command prompt.
    (2) in the column "Show" change the option to 'results '.
    (3) in the column "Column" change the formula of the column to a name like «filter 1"»
    (4) this column value to the variable in the presentation, such as FILTER1.
    (5) change the label for the column.
    (6) assign the filter in your report to the presentation FILTER1 variable.

    Repeat step 1 to 6 for the second filter.

    Kind regards
    Stijn

  • 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

  • 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

  • Entries are concatenated in the same column in the excel file

    Hi, I really need help in this emergency. The problem is when I open the spreadsheet file after you run the program below, all the values that I believe are concatenated in the same column. However, there are 2 different analog inputs which I want in 2 different columns. I'm getting the 2 waveforms in the same graph, but when I open the excel file, it seems that the entries are concatenated in the same column. Someone knows how to fix this? Thank you very much.

    Hi Ben 64,.

    Thanks a lot again. I did as you said and I removed the dynamic data and logged files added directly to the results. I'm still checking if the program works as I can branch only when I return to work tomorrow. Tell me if you think it might be able to work this time. Thanks a lot again!

  • Multiple constraints on the same column

    Hello experts, we can use Multiple forced on the same column in oracle as creating table, I want to add a key single and forced to check on the same column is this possible? Thanks in advance,

    If you want, seems to be possible

    CREATE TABLE t1

    (col1 VARCHAR2 (50))

    CONSTRAINT ck1 CHECK (col1 IN ('A', 'B', 'C'))

    CONSTRAINT PRIMARY KEY (col1) pk1

    );

  • Select literal values in the same column

    Hello
    like the practice:

    Select 'A', 'B', 'C' for double
    will select these values in their own column on the same line, is there a simple way to select these values in the same column on lines without first their insertion into a table?

    Thank you
    SQL> select 'A' x from dual union
      2  select 'B' x from dual union
      3  select 'C' x from dual ;
    
    X
    -
    A
    B
    C
    

    A bit complicated:

    SQL> select chr(ascii('A')+level-1) x
      2  from dual
      3  connect by level <=3;
    
    X
    -
    A
    B
    C
    

    Other:

    SQL> select regexp_substr('ABC','[[:alpha:]]',1,level) x
      2  from dual
      3  connect by level <= length('ABC');
    
    X
    ---
    A
    B
    C
    

    Max
    http://oracleitalia.WordPress.com

    Published by: Massimo Ruocchio, February 12, 2010 17:55
    added a second

    Published by: Massimo Ruocchio, February 12, 2010 17:58
    Added the third

  • apex5 pre-release - url filter applies to the two IRs with the same column name

    I've implemented 2 interactive reports on the same page, one on EMP (static id Throne) and the other on DEPT (deptir static id). Both the DEPTNO column. If I create the following filter via the URL: IR [throne] EQ_DEPTNO:20, the filter is applied to the two interactive reports.

    Screenshot from 2015-03-29 08:30:33.png

    Hello

    Please let us know. It has the same root cause as your other reported problem. It's bug #20764255, which has already been identified and corrected on our development environment. A fix will be released in our production release.

    Concerning

    Patrick

    Member of the APEX development team

    My Blog: http://www.inside-oracle-apex.com

    APEX Plug-Ins: http://apex.oracle.com/plugins

    Twitter: http://www.twitter.com/patrickwolf

  • Merge two csv files both with the same columns

    Hi all

    I have two csv files (attached) both with the same DS column headings that I seek to merge into a csv file. I am struggling to find a way to do it.

    The two files are already sorted by DS but have additional info not required in the column of the DS. What I need is a cmdlet that will read each column DS each csv, correspond to lines and combine in a csv file.

    Any help, advice, much appreciated.

    Best,

    Rob.

    Save the script in the current folder as join - Collections.ps1, then do

    $csv1 = Import-Csv LunUUIDtoDS.csv -UseCulture $csv2 = Import-Csv VMtoDS.csv -UseCulture
    .\Join-Collections.ps1 $csv1 "DS" $csv2 |
    Export-Csv mergedCSV.csv -NoTypeInformation -UseCulture
    
  • How can i two lists drop-down for the same column in OBIEE Dashboardprompt?

    Hello

    I need a report for a specific date range. I have to add 2 drop-down lists in the dashboardprompt for the same startdate and enddate column and the report must be filtered accordingly.

    I can't add two drop-down lists in the DATE column in the same dashboardprompt.

    How can I achieve this?

    Can anyone help?

    Hello

    You should be able to achieve the desired result by setting the operator for the column ' is between ' when you set the prompt.

    Kind regards
    Mark

  • Looking for a keyword using as a query that could contain several appearance in the same column

    I am facing a problem. A bunch of my JSP frontend code was stored in a few tables in my database (65 rows in a table), I have identified using a few queries. Now, I want to update a Href link, which is present in all of these motions. But since these entries in the column are very long (50 to 60 lines long) and it is possible that some lines may the link (which must be replaced), several times, I'm not sure if a query updated simple using a only as will work for her or not?

    Any suggestion/ideas are welcome.

    Please let me know if you need more info.

    Hello

    e5d4d744-cf66-4FE0-8353-bbd8fd826b21 wrote:

    I am facing a problem. A bunch of my JSP frontend code was stored in a few tables in my database (65 rows in a table), I have identified using a few queries. Now, I want to update a Href link, which is present in all of these motions. But since these entries in the column are very long (50 to 60 lines long) and it is possible that some lines may the link (which must be replaced), several times, I'm not sure if a query updated simple using a only as will work for her or not?

    Any suggestion/ideas are welcome.

    Please let me know if you need more info.

    Yes; whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements), so that people who want to help you can recreate the problem and test their ideas.

    Also post the results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.

    Simplify the problem as much as possible.  For example, if your strings are sometimes up to 4000 characters, you don't have to display all of the data that is almost as long.  You can probably show you want with strings that are 80 characters long.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002#9362002

    This statement:

    UPDATE table_x

    SET str = REPLACE (str

    old_link

    new_link

    )

    WHERE str LIKE "%" | old_link | '%'

    ;

    will change all the occurrences of old_link to new_link.  It will only change the lines where old_link occurs, but, aside from that, regardless of how many times old_link occurs in str: if it appears 2 times in the same str, two occurrences will be changed in new_link.

    Watch out for the problem ' mother is in chemotherapy.  If old_link is 'bar.com', the above statement will change "a".  You may need to REGEXP_REPLACE or REGEXP_LIKE if you need to consider what (if any) comes immediately before "bar.com' to decide or not to change it.

Maybe you are looking for

  • iMac - 10.11.4 - Bluetooth problem

    Hello I have 27 "iMac end of 2015 and it used to work great, but last month after put 10.11.4 at level, bluetooth does not work. I need to connect the cable to the keyboard on the first that I need to force restart of the keyboard and bluetooth back

  • Cannot install Windows Update error number 80070641 update

    original title: little Question on the error 80070641 update number Hi, I was wondering if someone help cam - I had a windows update to install the-(KB2596785) next, (KB2596843), (KB2596912), (KB2596789) all for microsoft office (2007) and powerpoint

  • Vista is stuck on the "Configuring updates" screen

    IM using vista, downloaded the latest updates, restart computer laptop to install them, returned a few hours later to find that its impasse on "Configuring updates 3/3" thing... it loads up to 98% and then restarts n stops... I tried the system resto

  • Conflict HSPA and Lan Wireless

    Hi, I have a dongle USB HSPA Sierra for internet access and home Asus Wifi network for file sharing.  When you try to connect to the internet with HSPA and Lan active, IE displays an error message from Asus.  Internet is only available with the Asus

  • Flashing arrow of blackBerry Smartphones

    I am a new owner of a Blackberry Bold 9900. I noticed that my phone looks like it is downloading something every so often that I can see the arrow at the top right of the screen flashing. Of course, I know it happens when I download, but why when the