Create table with overlapping parallel dates in individual columns

I try to combine data from two different tables into a single table.

The data in table 1 contains locations of patients in a hospital where each record represents a single location. Patients can be transferred several times between the different beds resulting from multiple records for a single visit.

The data in table 2 contains the operative activity of the patient to the Hospital where each record represents either the GOLD of the suspension of the recovery room. A patient may have multiple operations in a single visit.

I would like to join/merge/mashup data in a single table that contains the data parallel to each other. In other words, dates of the appliance on one side of the table and the activity of GOLD on the other. The difficulty is that the two sets of overlapping of dates of arrival and departure. I wish that the final table to divide the originals in new records when the overlaps do not coincide.

Example:

Original in both events (one per table)

> Unit event has - from 14:00 to 18:00

> OR event B - from 16:00 to 17:00

Results in 3 documents (in the final)

> Event 1 - unit from 14:00 to 16:00, null dates GOLD

> Event 2 - unit from 16:00 to 17:00 OR 16:00 to 17:00

> Event 3 - unit from 17:00 to 18:00, null dates GOLD

Of course overlap can be more complex than the example above and adding code to indicate the 'ghosts' transfers to as well.

In the code below, the first visit of the GOLD occurs during the first mention of the unit.

Jason

Oracle 10g

[code]

create the table delme_Unit_dates

(id varchar2 (20))

, unit_rcd_id varchar2 (20)

, Unit_desc varchar2 (20)

Unit_in_code char (1)

Date of Unit_in_dttm

Date of Unit_out_dttm

Unit_out_code char(1));

create the table delme_or_dates

(id varchar2 (20))

, OR_rcd_id varchar2 (20)

, OR_desc varchar2 (20)

OR_in_code char (1)

Date of OR_in_dttm

Date of OR_out_dttm

OR_out_code char(1));

create the table delme_all_dates

(id varchar2 (20))

, Unit_OR_id varchar2 (40)

, Unit_rcd_id varchar2 (20)

, Unit_desc varchar2 (20)

Unit_in_code char (1)

Date of Unit_in_dttm

Date of Unit_out_dttm

Unit_out_code char (1)

, OR_rcd_id varchar2 (20)

, OR_Desc varchar2 (20)

OR_in_code char (1)

Date of OR_in_dttm

Date of OR_out_dttm

OR_out_code char (1));

insert into delme_unit_dates values ('123456', 'U1111', 'Unit A', 'A', to_date('2013-04-29 5:02:00 PM', 'yyyy-mm-dd hh:mi:ss am'), to_date('2013-05-09 1:06:00 PM', 'yyyy-mm-dd hh:mi:ss am'), 'B');

insert into delme_unit_dates values ('123456', 'U1112', 'Unit A', 'B', to_date('2013-05-09 1:06:00 PM', 'yyyy-mm-dd hh:mi:ss am'), to_date('2013-05-09 4:53:00 PM', 'yyyy-mm-dd hh:mi:ss am'), 'B');

insert into delme_unit_dates values ('123456', 'U1113', 'Unit A', 'B', to_date('2013-05-09 4:53:00 PM', 'yyyy-mm-dd hh:mi:ss am'), to_date('2013-05-10 10:52:00 PM', 'yyyy-mm-dd hh:mi:ss am'), 't');

insert into delme_unit_dates values ('123456', 'U1114', ' unity, 't', to_date('2013-05-10 10:52:00 PM', 'yyyy-mm-dd hh:mi:ss am'), to_date('2013-05-11 11:30:00 AM', 'yyyy-mm-dd hh:mi:ss am'), 'B' ");

insert into delme_unit_dates values ('123456', 'U1115', ' unity, ' B', to_date('2013-05-11 11:30:00 AM', 'yyyy-mm-dd hh:mi:ss am'), to_date('2013-05-12 4:00:00 PM', 'yyyy-mm-dd hh:mi:ss am'), 'B');

insert into delme_unit_dates values ('123456', 'U1116', ' unity, ' B ', to_date('2013-05-12 4:00:00 PM', 'yyyy-mm-dd hh:mi:ss am'), to_date('2013-05-16 2:14:00 PM', 'yyyy-mm-dd hh:mi:ss am'),' t ');

insert into delme_unit_dates values ('123456', 'U1117', 'Unit Z', ', to_date('2013-05-16 2:14:00 PM', 'yyyy-mm-dd hh:mi:ss am'), to_date('2013-05-17 2:26:00 PM', 'yyyy-mm-dd hh:mi:ss am'), 'B');

insert into delme_unit_dates values ('123456 ', 'U1118', 'Unit Z', 'B', to_date('2013-05-17 2:26:00 PM', 'yyyy-mm-dd hh:mi:ss am'), to_date('2013-05-20 11:30:00 AM', 'yyyy-mm-dd hh:mi:ss am'),');

insert into delme_or_dates values ('123456', 'OR2221', 'or 1', 'O', to_date('2013-05-09 7:35:00 AM', 'yyyy-mm-dd hh:mi:ss am'), to_date('2013-05-09 10:56:00 AM', 'yyyy-mm-dd hh:mi:ss am'), 'R');

insert into delme_or_dates values ('123456', 'OR2222', ' 5', 'R', to_date('2013-05-09 10:56:00 AM', 'yyyy-mm-dd hh:mi:ss am'), to_date('2013-05-09 3:20:00 PM', 'yyyy-mm-dd hh:mi:ss am'), 'U');

insert into delme_or_dates values ('123456', 'OR3331', 'or 2', 'O', to_date('2013-05-16 7:59:00 PM', 'yyyy-mm-dd hh:mi:ss am'), to_date('2013-05-16 10:43:00 PM', 'yyyy-mm-dd hh:mi:ss am'), 'R');

insert into delme_or_dates values ('123456', 'OR3332', ' 8', 'R', to_date('2013-05-16 10:43:00 PM', 'yyyy-mm-dd hh:mi:ss am'), to_date('2013-05-17 11:20:00 PM', 'yyyy-mm-dd hh:mi:ss am'), 'U');

commit;

-Is far from what we

Select

U.*

, o.*

Of

delme_Unit_dates U

delme_OR_dates O

where

U.ID = o.id

and U.UNIT_IN_DTTM < = O.OR_IN_DTTM

and U.UNIT_OUT_DTTM > = O.OR_IN_DTTM

order of U.UNIT_IN_DTTM, O.OR_IN_DTTM

;

[/ code]

Post edited by: Jason_S (changed a single date ' 2013 - 05 - 16 15:20 ' to ' 2013 - 05 - 09 15:20 ')

Hi, Jason.

Jason_S wrote:

I edited one of the dates in the original post.

Also although the inpatient unit and OR events are contiguous for a given patient (no overlap and without gaps - after that data are cleaned).

...

The sample data you posted a of gaps in the data of the GOLD.  It is correct that the solution below works or not there are gaps in the two tables.

WITH got_dttm AS

(

SELECT unit_in_dttm AS DTMC

OF delme_unit_dates

UNION

SELECT unit_out_dttm AS DTMC

OF delme_unit_dates

UNION

SELECT or_in_dttm AS DTMC

OF delme_or_dates

UNION

SELECT or_out_dttm AS DTMC

OF delme_or_dates

)

all_periods AS

(

SELECT DTMC AS in_dttm

, (DTMC) ahead OF (ORDER BY DTMC) AS out_dttm

OF got_dttm

)

SELECT NVL (u.id, o.id) as id

u.unit_rcd_id

u.unit_desc

u.unit_in_code

p.in_dttm

p.out_dttm

o.or_rcd_id

o.or_desc

Of all_periods p

LEFT OUTER JOIN delme_unit_dates u WE u.unit_in_dttm<=>

AND u.unit_out_dttm > = p.out_dttm

LEFT OUTER JOIN delme_or_dates o WE o.or_in_dttm<=>

AND o.or_out_dttm > = p.out_dttm

WHERE p.out_dttm IS NOT NULL

ORDER BY p.in_dttm

;

You can use the query above to CREATE or a CREATE TABLE... AS command.

If you have as much data as you say, a table or materialized view would be maybe faster to use.

You will notice that I do understand not all columns; I would like to know if you have a problem, including them.

I don't know what id role plays in this problem.  It is difficult to say when all rows have the same value.

Tags: Database

Similar Questions

  • Table with fixed header and the left column

    I created a table in my application with the fixed left column (left most column is fixed and remaining columns are scrolling from left to right). is it possible to create a table with fixed position and fixed left column?

    Suppose there are 50 rows and 10 columns in my paintings, and only 3 columns and 15 rows are visiable on the screen

    (1) when the user scroll left to right left only most of the columns must be fixed. Remaining cap of the table and column scroll left to right and vice versa. also

    (2) when user scroll high high bottems single topic most must be fixed and remaining all lines (with to the left most column) should be scrollable.

    I am able to put in place a point at the top, but not both. Please suggest

    "If I repopulate the value in the cell when user scrolling, shell, I get scrolling effect correctly as it only shows half cell when the user highlight half of the cell."

    Approach using TablelayoutManager display single cells and scrolling would be cell at a time.  And Yes, you will need to override navigationMovement and n of methods appropriate TouchEvent your TableLayoutManager so that he knows when to fill the cells.

    Another alternative is to have four managers, we don't the the upper left corner (the dead angle), one to make the top row (column headings), one to make the left column (row headings), and the other to do the rest (data).  Place all these in a delicate header and line manager.  Only allow the user to scroll the data part.  Have the difficult Manager to listen the scroll events.  Then have the wily Manager add and remove the dummy column and header line managers as appropriate.  Note that these topic fields would not good passes, they would be either there or they would not be displayed. That would give you your 1/2 a scroll of the cell.  And you wouldn't have to substitute anything to detect movement, you would have left the listener do scrolling for you.

  • How to join two tables to retrieve the data from the columns in table two. Tables have primary and foreign key relationships

    Hello

    I want to join the two tables to retrieve the data from the columns of the two table passing parameters to the join query. Tables have primary and foreign key relationships

    Details of the table

    Alert-1 - AlertCode (FK), AlerID (PK)

    2 AlertCode-AlertDefinition-(PK)

    Help, please


    ----------

    Hi Vincent,.

    I think that you have not worked on adf 12.1.3.  In adf 12.1.3 you don't have to explicitly create the association. When you create the EO to your table, Association xxxxFkAssoc, will be created by ADF12.1.3 for you automatically. Please try this and do not answer anything... You can also follow the links below. I solved the problem by using the following link

    Oracle ADF Guide step by step - Oracle ADF tutorial: creating a relationship of the master / detail using Oracle ADF

    ---

  • Create table with several Collections of data control

    Hello

    I have a requirement about to display data in a table. It shows simple, but certain columns in the table are within a collection, and the others are in another collection. I read this chapter Creation of ADF Databound Tables - 11 g Release 1 (11.1.1.7.0), and she explains to create the table with a collection.

    I have no knowledge on the model, I know just as control data, so what should I do? :

    -Ask for the template designer to redraw the control of data to include a collection with all the data?

    -Try to work with the actual data control? If so, how can I create the table several Collections of data control?

    Plese let me know if there is another solution. I work with JDeveloper 11.1.1.7.

    Thank you!

    AAPDL

    Hello

    You can have a managed bean that e... g exposes an ArrayList of objects. This can then binds to the value property of the table. If the object sets the information of table row combination that you get multiple iterators (collections), then the table will display the joined data.

    Frank

  • Need to create a new line in the table with the same data as the primary key, but new PK

    Hello gurus,

    I have a table with a column as a primary key, I need to create a new row in the table, but with the same data in one of the lines, but with different primary keys, focus a double row with key primary diferent...

    Any ideas of how it can be done without much complication?

    Thanks in advance for your answer.

    Agress,
    Karim idrissi

    user9970447 wrote:
    Hello gurus,

    I have a table with a column as a primary key, I need to create a new row in the table, but with the same data in one of the lines, but with different primary keys, focus a double row with key primary diferent...

    Any ideas of how it can be done without much complication?

    Thanks in advance for your answer.

    Agress,
    Karim idrissi

    something like

    insert into mytable values ('literal for new pk',
                                           select non-pk-1,
                                                    non-pk-2,
                                                    non-pk-n
                                           from mytable
                                           where pk-col = 'literal for existing pk')
    
  • Syntex to create the table with the long data type

    I'm looking to create a table based on another table that having the column long data type. Throw the error ORA-00997: illegal use of the LONG data type


    I tired it

    create table abc_long (ag bgd long number);

    create table abc_long_dummy as ( ) Select *of abc_long); - ORA-00997 error: illegal use of the LONG data type

    How to get there?

    I'm looking to create a table based on another table that having the column long data type.

    You really don't want to do that.

    LONG data type has been deprecated for some time now, use CLOB.

    The TO_LOB() function will do the conversion on the fly:

    create table abc_long_dummy
    as
    select ag
         , to_lob(bgd) as bgd
    from abc_long ;
    
  • Create table with data in the column

    Create a new table, just want to know if there is a way to add a new column to the table with a value in all areas of this column when new rows are added to that this column will always be the same value

    As...

    name | address | zip | assets



    Active will always be Yes.
    I do a trigger?

    Use the default...

    create table (test)
    name varchar2 (20).
    address varchar2 (40),
    zip number (7).
    Active VARCHAR2 (3) DEFAULT NULL NOT 'yes');

  • Error creating table with clusters

    Hello
    I tried the following
    CREATE CLUSTER emp_dept (deptno NUMBER(3))
    Cluster is created

    Then I tried to create the table with the cluster above but giving error:
    create table emp10 (ename char(5),deptno number(2) )cluster emp_dept(deptno);
    The error is:
    ORA-01753 column definition incompatible with clustered column definition
    Could you please help me in this

    Your cluster is based on a NUMBER data type (3), while the emp10 table has a deptno column with a data type of NUMBER (2).

  • help with quierying, a table with varchar as dates

    the guys need a little help im close, but I can't just close the deal.
    I have a table that the field is dataytped as varchar2, but she holds a date as such date of today '20100615'.
    I know that the first thing that you guys are going to say is that this must be formatted as a date but it is not my table and I do deal with this.
    Here's how the problem im trying to query for a range of dates, and im having a hell of a time to do.
    as you cannot say my query below im trying to bring back only 15 days worth of data by date.
    can someone please point out what is obvious. I was home for a day now to try to get this working.



    SELECT DISTINCT to_date (fwvitals_date, 'YYYYMMDD') "fwvitals_date".
    OF fwvitals
    where fwvitals_date
    between (((SELECT MAX (fwvitals_date) OF FWVITALS)))
    Double ((SÉLECTIONNEZ to_CHAR (sysdate-15, «AAAAMMJJ»)))

    Hello

    user633029 wrote:
    the guys need a little help im close, but I can't just close the deal.
    I have a table that the field is dataytped as varchar2, but she holds a date as such date of today '20100615'.
    I know that the first thing that you guys are going to say is that this must be formatted as a date but it is not my table and I do deal with this.

    You are absolutely right!

    Here's how the problem im trying to query for a range of dates, and im having a hell of a time to do.
    as you cannot say my query below im trying to bring back only 15 days worth of data by date.
    can someone please point out what is obvious. I was home for a day now to try to get this working.

    SELECT DISTINCT to_date (fwvitals_date, 'YYYYMMDD') "fwvitals_date".
    OF fwvitals
    where fwvitals_date
    between (((SELECT MAX (fwvitals_date) OF FWVITALS)))
    Double ((SÉLECTIONNEZ to_CHAR (sysdate-15, «AAAAMMJJ»)))

    "WHERE x BETWEEN y AND z" is equivalent to
    "WHERE x > = y AND x.<=>
    If y > z, no line will never be allowed, and if there is the great artist of value in your table, then lines (probably) very little, perhaps only 1 will satisfy the same if condition z > y.

    What exactly are you trying to do?
    It helps if post you a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data. If the results are conditional, give some examples, for example, "if I run the query at any time on 15 June, I want to... but if it's June 16, so I want to..." »

    If you want the most recent 15 days, including today (that is, when run on 15 June, you want from 1 June until 15 June) then:

    SELECT DISTINCT
         fwvitals_date
    FROM      fwvitals
    WHERE       fwvitals_date     BETWEEN     TO_CHAR (SYSDATE - 14, 'YYYYMMDD')
                   AND     TO_CHAR (SYSDATE,      'YYYYMMDD')
    ;
    

    Fortunately, the strings are in a format such as sorting is explicit, so you don't have to run TO_DATE on each of them and get conversion errors.

    Published by: Frank Kulash, June 15, 2010 21:52

  • How to add the primary key for the table with the existing data?

    The table is already busy data. There was no primary key before, so for each column, there are some duplicate values.

    I want to add a new column, which should be of the integer data type and can automatically incremented, from 001. I tried with Oracle SQL Developer, but it says "ORA-01758: table must be empty to add mandatory (NOT NULL) column. How can I do? Thank you!

    Hello

    Look for the [ALTER TABLE | http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_3001.htm#sthref4803] command to find out how to add a column (step (1)) and a (step (3)) constraint to an existing table.

    For the step (2):

    CREATE SEQUENCE  employee_id_seq
    START WITH  1
    ;
    
    UPDATE  employee
    SET     id  = employee_id_seq.NEXTVAL;
    

    When you create a sequence, START WITH 1 is the default value, so that the line is not really necessary above... I've included just to show how you could start with any number you have chosen.

  • Creating tables with Muse...  Excel copy / paste?

    Can I create a table with Muse?

    I have no knowledge of HTML... learning HTML can be a good idea, but I don't really have time for that right now.

    Can I add a table Excel for Muse?  Or y at - it a simpler way to create the table with the Muse?

    You can insert page Muse excel table or use any html generator to create a table and use the exit code.

    This thread will provide the exact steps for inserting table on page Muse of excel:

    https://forums.Adobe.com/thread/1364446?TSTART=0

    With html generator, you will not need to define or add any code on your side, just select the options you want in your table and then copy the code insert html into the page of Muse.

    http://www.tablesgenerator.com/html_tables

    Thank you

    Sanjit

  • ADF table with checkbox refresh data binding problem

    Hello.

    I use JDeveloper 11.1.1.3. I need to use the table with checkboxes in each row of the table in my project. I use VO with transitional 'Selected' attribute that has a boolean type.
    Everything works well, wait one thing:
    When you click checbox with valueChangeListener and try to get the selected line in the managedBean you won't get any selected lines. After selecting second maaged bean evil shows that 1 single line is selected. It's my managedBean method:

    public void SelectCountyClick (ValueChangeEvent valueChangeEvent) {}

    DCIteratorBinding it = ADFUtils.findIterator (ITERATOR_NAME);

    int selectedRowCount = 0;
    RowSetIterator laughs = it.getRowSetIterator ();
    Line r = rit.first ();
    If (r! = null) {}
    If ((Boolean) r.getAttribute ("Selected"))
    selectedRowCount ++;
    }

    While (rit.hasNext ()) {}
    r = rit.next ();
    If ((Boolean) r.getAttribute ("Selected"))
    selectedRowCount ++;
    }

    System.out.println ("selected all THE LINES:" + selectedRowCount);


    }

    I tried to change this event to the client event, I got the line number, I put 'true' or 'false' to the code data binding, but whenever I can't correct data after the value change event.

    Please help me.

    The latest idea is updated databing after click of checkbox, I think. Please help me.

    Thank you!

    You must go through the concepts of life cycle of page ADF. In simple terms the Boolean value in the model is not defined in valueChangeListener. Try adding (.processUpdates) valueChangeEvent.getComponent (FacesContext.getCurrentInstance ()); on top of your listener method and see the effect.

    Reference:
    http://docs.Oracle.com/CD/E15051_01/Web.1111/b31974/adf_lifecycle.htm

  • create table with references to values in another schema

    Experts,

    Is it possible to create the table in a schema with the references pointing to column values in a different pattern?

    Say, I have 2 diagrams A and B

    Has the employee table and and B dept table, I want to run him below modifies the declaration, it will work?

    ALTER TABLE A.EMP ADD)
    FOREIGN KEY (DEPT_ID)
    REFERENCES B. DEPARTMENT (DEPT_ID));

    I know there is no sense in doing this, still would like to know to make a temporary workaround solution.

    Kind regards
    LIBERATOR

    Published by: manon on October 21, 2011 12:30 AM

    Yes it is possible with the right privilege:

    SQL> grant connect, resource to a identified by a;
    
    Grant succeeded.
    
    SQL> grant connect, resource to b identified by b;
    
    Grant succeeded.
    
    SQL> connect b/b
    Connected.
    SQL> create table p (x int primary key);
    
    Table created.
    
    SQL> grant references on p to a;
    
    Grant succeeded.
    
    SQL> connect a/a
    Connected.
    SQL> create table c (y int);
    
    Table created.
    
    SQL> alter table c add foreign key (y) references b.p(x);
    
    Table altered.
    
  • How to create personalized with a dynamic date stamps

    I tried to create a customized with a dynamic date stamp. But the date is not dynamic. Help, please

    There are a number of things that need to be properly configured for a stamp to work as a dynamic stamp, form the name of template to the calculation script. If you provide the details of how you set the PDF stamp, it would be useful, as would the next book that has all the information you need: www.amazon.com/About-Stamps-Acrobat® - without paper-Workflows/dp/0985614706 /.

  • Creating tables with the same Structure and with the remote control FOR the parts database

    Hello

    I have a remote DB connection and a local DB connection in my system
    I want to create the same Table and data from my DB remote to Local Connection DB connection.

    Please tell me how to do this?

    CREATE TABLE LOCAL_TABLE AS SELECT * FROM REMOTE_TABLE@TNS_ALIAS;

Maybe you are looking for