Insert table when missing data

Hello
I have the following table, for readability I cracked the after each manager for each file number. The last column is the cumulative sum of the second last column. Value for month should ideally go 1 - 3 (as we see in both cases to Chicago). But the table, you can see in some cases, some entries are missing (marked by <-).

CITY CASE_NUMBER CASE MANAGER MONTHS MONTHLY_TOTAL FISCAL_TOTAL
---------------------------------------------------------------------------
Chicago case_1 1 John 1 2 2
Chicago case_1 1 John 2 3 5
Chicago case_1 1 John 3 5 10

Chicago case_1 Jeff 1 4 4 1
Chicago case_1 Jeff 2 2 6 1
Chicago case_1 Jeff 3 3 9 1

Chicago case_2 John 2 1 3 3
Chicago case_2 John 2 2 2 5
Chicago case_2 John 2 3 4 9

Chicago case_2 Jeff 2 1 2 2
Chicago Jeff 2 2 7 9 case_2 < -.

NewYork case_1 1 Lee 1 3 3
NewYork case_1 Lee 2 4 7 1 < -.

case_1 NewYork 1 Sue 1 2 2
case_1 NewYork 1 Sue 2 3 5
case_1 NewYork 1 Sue 3 2 7

NewYork case_1 Lee 2 1 2 2
NewYork case_1 Lee 2 2 4 6
NewYork case_1 Lee 2 3 4 10

NewYork case_1 Sue 1 3 3 2
NewYork case_1 2 Sue 2 2 5 < -.


What I want is first find the missing lines and insert values. To find those missing monthly_total = 0
fiscal_total = value of the previous row. For example, for the missing first line should be:

CITY CASE_NUMBER CASE MANAGER MONTHS MONTHLY_TOTAL FISCAL_TOTAL
---------------------------------------------------------------------------
Chicago case_2 2 3 0 9 Jeff
with t1 as (
            select  case_number,
                    max(month) month_count
              from  tbl
              group by case_number
           ),
     t2 as (
            select  case_number,
                    column_value month
              from  t1,
                    table(
                          cast(
                               multiset(
                                        select  level
                                          from  dual
                                          connect by level <= month_count
                                       )
                               as sys.OdciNumberList
                              )
                         )
           )
select  max(city) over(partition by t2.case_number,manager) city,
        max(case) over(partition by t2.case_number) case,
        t2.case_number,
        t.manager manager,
        t2.month month,
        nvl(monthly_total,0) monthly_total,
        last_value(fiscal_total ignore nulls) over(partition by t2.case_number,manager order by t2.month) fiscal_total
  from      tbl t
          partition by(manager)
        right join
            t2
          on (
                  t2.case_number = t.case_number
              and
                  t2.month = t.month
             )
  order by t2.case_number,
           manager,
           month
/

CITY    CASE   CASE_NUMBER MANA      MONTH MONTHLY_TOTAL FISCAL_TOTAL
------- ------ ----------- ---- ---------- ------------- ------------
chicago case_1           1 Jeff          1             4            4
chicago case_1           1 Jeff          2             2            6
chicago case_1           1 Jeff          3             3            9
chicago case_1           1 John          1             2            2
chicago case_1           1 John          2             3            5
chicago case_1           1 John          3             5           10
newyork case_1           1 Lee           1             3            3
newyork case_1           1 Lee           2             4            7
newyork case_1           1 Lee           3             0            7 <-- missing row
newyork case_1           1 Sue           1             2            2
newyork case_1           1 Sue           2             3            5

CITY    CASE   CASE_NUMBER MANA      MONTH MONTHLY_TOTAL FISCAL_TOTAL
------- ------ ----------- ---- ---------- ------------- ------------
newyork case_1           1 Sue           3             2            7
chicago case_2           2 Jeff          1             2            2
chicago case_2           2 Jeff          2             7            9
chicago case_2           2 Jeff          3             0            9 <-- missing row
chicago case_2           2 John          1             3            3
chicago case_2           2 John          2             2            5
chicago case_2           2 John          3             4            9
newyork case_2           2 Lee           1             2            2
newyork case_2           2 Lee           2             4            6
newyork case_2           2 Lee           3             4           10
newyork case_2           2 Sue           1             3            3

CITY    CASE   CASE_NUMBER MANA      MONTH MONTHLY_TOTAL FISCAL_TOTAL
------- ------ ----------- ---- ---------- ------------- ------------
newyork case_2           2 Sue           2             2            5
newyork case_2           2 Sue           3             0            5 <-- missing row

24 rows selected.

SQL> 

SY.

Tags: Database

Similar Questions

  • Trying to update a table in a second table when the data are different

    Hello;
    I have a the same table in two databases. The database are connected with a DB link. I'm trying to update one table based on the data in the second table when the EMP_ID is but the name does not match.

    The table will look like:
    Table name: EMP
    EMP_ID
    LAST_NAME
    FIRST NAME
    MIDDLE_INITIAL

    My SQL is:
     
    update EMP TARGET 
        set (TARGET.LAST_NAME, TARGET.FIRST_NAME,TARGET.MIDDLE_INITIAL) = ( 
            select SOURCE.LAST_NAME, SOURCE.FIRST_NAME, SOURCE.MIDDLE_INITIAL 
            from EMP@OTHER_DB SOURCE where 
            TARGET.PHYSICIAN_ID = SOURCE.PHYSICIAN_ID 
            and TARGET.LAST_NAME <> SOURCE.LAST_NAME); 
    This refers to a number of update of all lines not the bit I want.

    Any help would be great!

    Hello

    Sky13 wrote:
    Hello;
    I have a the same table in two databases. The database are connected with a DB link. I'm trying to update one table based on the data in the second table when the EMP_ID match

    Do you doctor_id?

    but the name does not match.

    The table will look like:
    Table name: EMP
    EMP_ID
    LAST_NAME
    FIRST NAME
    MIDDLE_INITIAL

    My SQL is:

    
    update EMP TARGET
    set (TARGET.LAST_NAME, TARGET.FIRST_NAME,TARGET.MIDDLE_INITIAL) = (
    select SOURCE.LAST_NAME, SOURCE.FIRST_NAME, SOURCE.MIDDLE_INITIAL
    from EMP@OTHER_DB SOURCE where
    TARGET.PHYSICIAN_ID = SOURCE.PHYSICIAN_ID
    and TARGET.LAST_NAME <> SOURCE.LAST_NAME); 
    

    This refers to a number of update of all lines not the bit I want.

    Any help would be great!

    There is no WHERE clause in the UPDATE statement, so that each row in the target table will be changed.
    If you only want to change the lines that have a match in the source table, then add a WHERE clause (perhaps "WHERE EXISTS (...)) with a subquery miuch very similar to the one you already have), or use the MERGER instead of UPDATE.

    If you want to know, post CREATE TABLE and INSERT statements to recreate the tables they existed before the UPDATE and also post the contents of the table changed after the UPDATE.
    Always tell what version of Oracle you are using.

    Maybe you want something like this:
    {code}
    MERGE INTO the emp target
    WITH THE HELP OF)
    SELECT o.emp_id
    o.last_name
    o.last_name
    o.middle_initial
    OF emp@other_db o
    JOIN emp t ON o.emp_id = t.emp_id
    AND o.last_name! = t.last_name
    ) source
    WE (target.emp_id = source.emp_id
    WHEN MATCHED THEN UPDATE
    SET target.last_name = source.last_name
    target.first_name = source.first_name,
    target.middle_initial = source.middle_initial,
    ;
    {code}
    assuming that emp is unique, at least in other_db.

    It will work in Oracle 10 (and more). In Oracle 9, MERGER still requires a WHEN MATCHED clause, so add one if you must. No matter what he does; the subquery USE will only return matches.

    Published by: Frank Kulash, October 10, 2011 16:45

  • How insert/DML data in the table when the data in the related table changes

    Hello guys!

    I came across a problem that I need to get fixed. Because I don't know how to start and get it resolved I wanted to ask you for your expertise.

    The scenario is as follows:

    I have a table 'a' in my 10g database and a view "ab" which combined table 'a' with 'b' table in a view. However, the 'b' table is a table in another schema Manager database. and accessible (read only right) via a database link.

    Now here it is: whenever the data changes in table "b", for example 2 new sets of data is inserted, I need to insert automatically the 2 values of these 2 sets of data in my table "a". Same procedure for update and delete in table "b".

    The action that inserts data into the table 'a' must be initialized in my database, I have limited access to the other. Can I somehow use a trigger my reviews of "ab" to insert data into the table "a"? Or is it possible to use the "change notification procedure database" using the view as the reference?

    Desperately need help and example of all suspicion/code greatly appreciated. I am very new to Oracle and not very fond of PL/SQL routines. So please be so kind as to give me more details.

    Thanks in advance - I hope you have any ideas how I can get this problem resolved.

    Sebastian

    >

    ... it does not, since the DDL operations are not permitted on the remote databases (ORA-02021). I can't create the trigger on a view either. :-(
    So what ways are left to insert data into the table 'a' when the related table changes?

    Please, help if you have an idea!

    Yes,
    You can't perform the DDL (create the trigger...) on remote databases as you can see...
    Try to create this trigger in the local database that will make DML (insert into...) on the remote database.

        CREATE OR REPLACE TRIGGER local_forward_pt_after_insert
         AFTER INSERT
             ON N2K_INV_PT
             FOR EACH ROW
    
         BEGIN
             -- Insert records into table "a"
             INSERT INTO TBL_PUNKTDATEN@remote_database_sid
              ( INT_NUMMER,
                STR_GEBIET
                 )
             VALUES
              ( :new.INT_INV_PT_NR,
                :new.GEBIET );
         END;
    

    Thank you

    Good luck

  • Display an empty table row of data when the data is not present

    Hello

    Can u please tell me How to display a row of data empty table when the data is not present?

    in my case the column header appears as the code below.

    <? If: SD_Type_Data_ID3 = 'KH '? > <? If: SD_SpecialHandlingCode_SPHD_ID17 = 'H '? > <? for each: Supplemental_Data_S17? > <? end if? >

    can u pls help me.

    Thanks and greetings

    Sylvie Kumar

    You can insert a fictitious line. Have an if condition in it, to show only when condition does not satisfy.

  • resize the text field or table row, column data

    Hi all

    I am facing a problem, not able to display all the data in the table when the data is larger than the height and width of the cell

    Is it somehow so that the line and deposited text get automatic size according to the data.

    Thank you

    Abhijit

    Usually, you must expand to accommodate for the height and width of the TextField. If you check this box, the textfield will be autosize, itself based on data at run time.

    Thank you

    Srini

  • Apex data load configuration missing table when importing to the new workspace

    Hi everyone knows this show before and have a work around.

    I export / import my request for a different workspace, and everything works fine except for 1 loading tables data.

    In my application, I use tables of data loading, and it seems that the latter do not properly Setup for the table object to load data. This causes my application to fail when the user tries to download a text file.
    Does anyone have a work around next to recreate the table of data load object?

    Breadcrumb: Components shared-> load data tables-> add modify data load table

    The app before exporting displays Workspace: OOS
    Single column 1 - CURRENCY_ID (number)
    Single column 2 - month (Date)

    When I import the app in the new workspace (OOS_UAT) data type is absent.
    Single column 1 - CURRENCY_ID
    Single column 2 - MONTH

    When I import the same workspace app: OOS I do not know this problem

    Version of the apex: Application Express 4.1.1.00.23

    Hi all

    If you run 4.1.1 it was a bug 13780604 (DATA DOWNLOAD WIZARD FAILED if EXPORTS of OTHER workspace) and have been fixed. You can download the fix for 13780604 (support.us.oracle.com) and the associated 4.1.1

    Kind regards
    Patrick

  • Insert the page elements when loading data

    Hi all

    I use APEX 5.0 and using wizard to load data to download the data.

    My table has 7 fields and I need to insert 3 fields in the table while loading data.

    I have created a process after Parse the data downloaded as below.

    The result is that the 5th field will be First Row column as 'Y' and no 6th and 7th column.  There is value of 5th field only.

    When click on next to data validation page, it shows the 5th field with column field and 6th without the name of the column.

    Please help me to the point where I must change my code.

    BEGIN
    APEX_COLLECTION. ADD_MEMBER)
    p_collection_name = > 'PARSE_COL_HEAD ',.
    p_c001 = > 'HUBCODE ',.
    p_c002 = > 'UPLOAD_FILENAME ',.
    p_c003 = > 'UPLOAD_DATE');

    FOR UPLOAD_ROW IN (SELECT SEQ_ID
    OF APEX_COLLECTIONS
    WHERE COLLECTION_NAME = "SPREADSHEET_CONTENT")
    LOOP
    APEX_COLLECTION. () UPDATE_MEMBER_ATTRIBUTE
    p_collection_name = > 'SPREADSHEET_CONTENT ',.
    p_seq = > UPLOAD_ROW. SEQ_ID,
    p_attr_number = > '5',.
    p_attr_value = >: P2_HUB_CODE);

    APEX_COLLECTION. () UPDATE_MEMBER_ATTRIBUTE
    p_collection_name = > 'SPREADSHEET_CONTENT ',.
    p_seq = > UPLOAD_ROW. SEQ_ID,
    p_attr_number = > '6'.
    p_attr_value = >: P2_FILE_NAME);

    APEX_COLLECTION. () UPDATE_MEMBER_ATTRIBUTE
    p_collection_name = > 'SPREADSHEET_CONTENT ',.
    p_seq = > UPLOAD_ROW. SEQ_ID,
    p_attr_number = > '7'.
    p_attr_value = > SYSDATE);

    END LOOP;
    END;

    Want to close this loop and hope that it will be useful for others.

    In the end, I managed download document using the latest plugin for APEX 5.0 excel2collections.

    As MK pointed out, I can control my data using the plugin.

    Another point more directly is users can download xls or xlsx files, do not need to convert them to csv format before downloading.

    I thank all of you for the help.

  • How can I insert the apex user id in the table when connecting?

    Hello

    I created a database with SSO on application. As you know because, single-sign - on my users don't need to enter name of user and password to log into the application. When a user in my application login ID (email add) automatically appears in the upper right automatically. My question is how can I capture user ID in the user's my table when a connection of the user in the application?

    Appreciate any help.

    Thank you

    Mohammad

    Maybe my solution:

    1. Application-shared logic components, you have processes of the article.

    2. create processes with process Point: on the new Instance and text:

    declare
    l_exists integer;
    begin
    select count(*) into l_exists from user_objects
      where object_type = 'TABLE'
      and object_name = 'AUDIT_USERS' AND ROWNUM=1;
    if l_exists = 0 then
    execute immediate 'CREATE TABLE  AUDIT_USERS
           (WHEN DATE,
              USER_NAME VARCHAR2(30)
           )';
    end if;
    insert into AUDIT_USERS values (sysdate, v('APP_USER'));
    end;
    

    Concerning

    Ziut

  • How can insert different types of data in the table?

    Hello
    How can I insert different types of data in the table, (e.g., numeric and string) in the same index of a table.

    example:
    index0 car 10 green

    car red 11 index1
    Index2 car Blue 12

    where green car red and blue car as string and 10, 11 and 12 in the numeric form.
    then I extracted 10, 11 and 12 a digital table

    and, the green car, red car, blue car in a string array

    Help!

    Use 'Analysis of the chain' as in the picture as an attachment.  This will extract the number and color that you can add tables later.

  • Among the data tables is missing from the 11g database. How to restore?

    Hello

    In my development 11G database, one database of tables is missed on Sept. 4.

    I have available valid RMAN backups, to restore the missing data in table I intend to do the following steps:-

    (1) create a new database
    (2) restore the fresh 3 taken rman sep to the DB Backup
    (3) now take the export of backup in the table whose data are not being met since the new database
    (4) import the exported backup of the old DB table.


    Is it the right way, I think? or any other alternative method that we have?

    Please suggest.


    Thanks in advance,
    Florine Reddy
    1) Create a fresh DB
    2) Restore the rman backup taken on 3rd sep to the fresh DB
    3) Now take the export backup of the table which the data is missed from the new DB
    4) Import the exported backup of the table to the old DB.
    

    fix!

  • Missing dates in the table

    Hello

    I have a table that could have a record for the day with the sale of information, but for some reason, there are missing dates, is it somehow I could find the witch dates are missing.

    Example table:

    Sales_Date | value
    2010-01-01 | 20
    2010 01-02 | 30
    04-01-2010 | 40

    The output of the query by the example above could only return the missing date (2010-01-03).

    Thanks in advance

    Might be a way

    SQL> with t as
      2  (
      3  select to_date('2010-01-01','YYYY-MM-DD') sales_date, 20 val from dual union all
      4  select to_date('2010-01-02','YYYY-MM-DD'),30 from dual union all
      5  select to_date('2010-01-04','YYYY-MM-DD'),30 from dual union all
      6  select to_date('2010-01-06','YYYY-MM-DD'),30 from dual union all
      7  select to_date('2010-01-07','YYYY-MM-DD'),30 from dual union all
      8  select to_date('2010-01-12','YYYY-MM-DD'),40 from dual
      9  )
     10  select (select min(sales_date) from t)+ level-1  dt from dual
     11  connect by level <= (select max(sales_date) - min(sales_date) from t)+1
     12  minus
     13  select sales_date from t order by 1
     14  ;
    
    DT
    -----------
    1/3/2010
    1/5/2010
    1/8/2010
    1/9/2010
    1/10/2010
    1/11/2010
    
    6 rows selected
    
    SQL> 
    
  • insert into the table using dynamic data

    Oracle form 6i
    Hai

    I need to insert data into a table. I have generated my data text file with data in a form, now I need to insert data into a table. How can insert my field at that table if it is given in the table, I need to update, and there is no data I need to insert... Pls tell me the solution...

    Concerning

    Srikkanth.M

    Create the trigger of the sur-insert and check the data are thre or not through the value of the primary key in this trigger. If the data is thre then update or it is then do not insert in the same trigger.

    Thank you
    SUN

  • Data pump import - can I can the name of the table when importing only?

    It is possible to use data pump export on a table name, and then import (add lines) at a table of different table with the same structure of exact column? I don't see a way to change only the name of the table when importing.

    Hello

    From 11.1 you can remap a table name. Use:

    remap_table = old_name:new_name

    Thank you

    Dean

  • How to store field data calculated in a table when a user disconnects?

    Hello

    I have a report with the following SQL statement.
    Past_Due and Task_Count are calculated fields.
    How can I store their data in a table when a user disconnects?

    Select
    p.ID,
    p.Name,
    p.Description,
    p.assigned_to,
    p.start_date,
    p.Finish_Date,
    p.target_date,
    CASE
    WHEN P.target_date < SYSDATE AND P.finish_date IS NULL THEN round (SYSDATE - P.target_date)
    WHEN P.target_date < P.finish_date THEN round (P.finish_date - P.target_date)
    0 OTHERWISE
    END Past_Due,
    p.Status,
    p.updated_by,
    p.updated_on,
    p.Note,
    Count (t.ID) task_count
    pm_project p, pm_task t
    where
    p.ID = t.project_id (+)
    P.id group,
    p.Name,
    p.Description,
    p.assigned_to,
    p.start_date,
    p.Finish_Date,
    p.target_date,
    CASE
    WHEN P.target_date < SYSDATE AND P.finish_date IS NULL THEN round (SYSDATE - P.target_date)
    WHEN P.target_date < P.finish_date THEN round (P.finish_date - P.target_date)
    0 OTHERWISE
    END,
    p.Status,
    p.updated_by,
    p.updated_on,
    p.Note

    -----
    H5. FYI, I am very new to SQL, PL/SQL, and APEX. Would appreciate much more explanation and full path (for example. Shared components > change the security attributes > VPD)

    Hello

    Past_Due and Task_Count are calculated fields and are therefore useless.
    You must not store redundant data (in general).
    Your past_due also uses a reference to sysdate, so the value is today different from tomorrow. You expect the database to change the value from one day to the next?
    So keep the data where it is and display calculated to your users using your query fields (oher options are available, but you already have the request I will not go in the).

    Greetings,
    Roel
    http://roelhartman.blogspot.com/
    You can reward this response in marking it as useful or Correct ;-)

  • Point cloud with missing data and 3 sets of data

    Hello

    I'm doing a scatter diagram that has 3 sets of data in it (i.e. 3 plots on the same graph), except that 2 of my sets of data have a missing value while my third set has all the values. I end up getting 2 lines that are disconnected. I can't just remove the line containing the missing data for the 2 sets of data because since my category axis is time, my data points get shifted and no longer appear at the right time. This is the chart that I have.

    Thank you.

    Hi Gabrielle,.

    If there is a diagram of dispersion, the x axis is a value axis. If you have auto selected for the min and max values on this axis, the scale may change when you remove the data point, 15, 85, but the rest remains in the same position relative to the values on each axis of ordinates. What change will be , however, is the curve on which 15 85 approached a local y maximum.

    Scatterplots will always leave a gap in the line/curve of connection where there are a pair of missing data. There are two ways to close the gap.

    If the chart is an essentially linear relationship, you can use a calculated value is pair up with the lack of value x. The downside of this is that the representation of this point will be indistinguishable on the map of the other data points, measured.

    A better way would be to make two tables, one with the full data set, the other with the partial sets, but with the pair missing completely removed.

    Adjust the cards the same size and have the same scales on each axis, then just remove one of the cards except the data points, the curves connecting the data points, the x axis of ordinates and the legend showing the color and the forms used to plot each series.

    Give a graphic a transparent filling and place it in front of the other.

    Kind regards

    Barry

Maybe you are looking for