By comparing the timestamp... columns i.e. cash matches between several passes

I have a table with 10 columns to date (each date comes from a different data source) and would like to compare how "matches" (with a tolerance of time given... say 1 hour) between each of the columns.

The result would be a matrix of 10 x 10 of values containing counts of correspondences between all combinations of date columns:
  
Matches found:
    A  B  C
A | 5  4  2
B | 4  5  3
C | 2  3  4  ** updated C-C from 5 to 4 because of potential null values in data
I started using the box instructions, but I realize how much I would need to use and am sure someone out there has a better approach. Looks like some kind of self-join is useful?

Any ideas?

Published by: user8720636 on 25 Sep, 2009 08:13

Hello

AJ_son wrote:
This solution works, but I was expecting a more 'elegant' way of managing the 10 x 10... I suspect that it may increase even more grand in the future.
If there is no other ideas, I'm going with this method. Thank you.

Yes, something less heavy is possible.
Your original approach (comparing each column against each column) required c ^ 2 ^ comparisons (where c is the number of columns to date), and solution requred a c extra DECODE expressions of Boneist (each with branches c) pivot the data in the form that you want. So the complexity was in the order of 2 c ^ 2 ^
Here is another way, which requires a CASE statement with branches c for data of the Nations United hub, and c. BOX simple expressions to convert data back and forth, making the total complexity 2 c.

WITH   cntr        AS
(
     SELECT     LEVEL     AS n
     FROM     dual
     CONNECT BY     LEVEL <= 3
)
,     unpivoted_data         AS
(
     SELECT     DENSE_RANK () OVER (ORDER BY t.ROWID)     AS rnum          -- use primary key instead of ROWID if you have one
     ,     cn.n
     ,     CASE     cn.n
               WHEN  1  THEN  t.date_1
               WHEN  2  THEN  t.date_2
               WHEN  3  THEN  t.date_3
          END                         AS dt
     FROM          cntr          cn
     CROSS JOIN     temp_dates     t
)
SELECT       r.n                         AS date_checked
,       COUNT (CASE WHEN c.n = 1 THEN 1 END)     AS against_date_1
,       COUNT (CASE WHEN c.n = 2 THEN 1 END)     AS against_date_2
,       COUNT (CASE WHEN c.n = 3 THEN 1 END)     AS against_date_3
FROM       unpivoted_data      r
JOIN       unpivoted_data      c     ON     r.rnum     = c.rnum
                           AND     r.dt     BETWEEN      c.dt - :dif
                                   AND      c.dt + :dif
GROUP BY  r.n
ORDER BY  r.n
;

Ann: dif is the permissible difference in days (for example ": dif: = 1/24;" means an hour).

I have a table with 100 rows that I use instead of subqueries as cntr. It makes requests like that, but a little shorter and simpler, probably not any faster.

If you are really looking for elegance, then maybe your data should be stored in the non swivel form in the first place. The fact that it makes sense to compare each column with the other column indicates that they are not so much attribute of another entity, as entities themselves. If you have stored data in a table that looked like the unpivoted_data above subquery, then you only need the main request.

Tags: Database

Similar Questions

  • ORA-1866 when you try to change the precision of the timestamp column

    Hello

    I use Oracle XE. I have a table that contains a Timestamp column. "Fractional precision" is 6 and "Time zone" has the value of HOURS LOCAL time ZONE.
    If I try to change the precision of the timestamp column (set to 2 for example), I get the following error:

    Error ORA-1866: the dattime class is not valid.
    The following SQL statement failed:
    ALTER TABLE CLIENTS
    CHANGE ("TIME_STAMP" TIMESTAMP (2) WITH THE LOCAL TIME ZONE)

    Please notify.
    Thank you
    MR. R.

    The column is empty? It should be just by reducing the precision.
    Try to run the command in the SQL Plus tool if you have not already done.

    The following should do the job

    ALTER TABLE CLIENTS ADD TEMPCOL TIMESTAMP (2);
    UPDATE CUSTOMER SET TEMPCOL = "TIME_STAMP";
    ALTER TABLE CLIENTS REMOVE THE COLUMN "TIME_STAMP";
    ALTER TABLE CLIENTS RENAME COLUMN TEMPCOL TO "TIME_STAMP";

    Concerning

    Published by: thriller on April 7, 2009 17:22

  • Rows based on the timestamp column

    Hi Experts

    I'm trying to get the last 3 records based on the timestamp column. But I am not able to understand where I should start... ?

    To make it more clear

    I have the following data
    id date
    1  07/03/09 3:57:55.000000 PM
    2  08/03/09 9:23:55.000000 PM
    3  05/03/09 7:53:55.000000 PM
    4  08/03/09 5:41:55.000000 PM
    5  06/03/09 8:50:55.000000 PM
    I want to
    2  08/03/09 9:23:55.000000 PM
    4  08/03/09 5:41:55.000000 PM
    1  07/03/09 3:57:55.000000 PM
    Thanks and greetings
    Saurabh Sharma
    select *
      from (
    select *
      from x
     order by dt desc
     )
      where rownum <= 3
    

    Published by: Alex Nuijten on March 10, 2009 11:31

  • by comparing the timestamp

    Hi I need to compare in timestamp with microseconds in other words precition:

    Select * from any_table where
    TO_TIMESTAMP (DT_INSERIMENTO, ' dd/mm/yyyy HH24:MI:SS, FF6') = to_timestamp (October 27, 2011 16:18:36, 346560 ', ' dd/mm/aaaa HH24:MI:SSxFF9')


    and the game has just the line that fulfills the condition,
    so I don't want in the line with in the dt_inserimento column result set a different value
    2011-10-27 16:18:36, 346560
    for example line with
    2011-10-27 16:18:36, 444450

    How can I accomplish this?

    Thank you
    Francesco
    Italy

    If this is the case, what about something like that?

    SELECT *
    FROM   any_table
    WHERE  dt_inserimento = TO_TIMESTAMP('27/10/2011 16:18:36.346560','dd/mm/yyyy HH24:MI:SSxFF9')
    

    If dt_inserimento is already a TIMESTAMP, you need not use the TO_TIMESTAMP function.

  • Loading data: formatting of data for the timestamp column

    Hi all

    I have a table with a timestamp column, named created_date. I want to download this table data using load data page. but there is a problem when downloading data, I have a csv file in which data column created_date in two different format as follows,

    03/09/2013-03:33

    02/09/2013-15:24

    the above data throws an error ORA-01821: date format not recognized.

    In Data / Table Mapping page, I tried with HH12:MI MM/DD/YYYY: SS AM. What format should I use for am and pm?


    Please help me solve...

    Thanks in advance

    Lacombe

    I solved it by using the format MM/DD/YYYY HH:MIAM.

    Thank you

    Lacombe

  • reading the timestamp column in the txt file

    Hi pros labview

    I work with labview 8.6 for about 1 week and I need help in reading txt files.

    the textfiles that I read have 2-11 columns.

    the first column shows the time and others show different channels where I measured the voltages.

    It is therefore no problem with reading of the voltage-columns and put it on the y - axis to a chart of the vi but I can't the time on the x-axis column.

    I took the basic "read file.vi" and it has changed a little according to my needs.

    hope you can help me, getting time on the x-axis column. (perhaps with a xy chart?)

    the vi and I have to read txt file are attached...

    Here is an example. The formatting of the x axis relative time will now do something.

  • How to create a default value for the timestamp column?

    I am trying to create a table with a default value to a timestamp column, can it be done?


    CREATE TABLE matbl
    (
    Default TIMESTAMP WITH time ZONE SCHEDULE date FutureDateTime ' 23:23:59.000 2999-12-31'
    )

    incorrect data type. try rather timestamp with time zone.

    CREATE TABLE myTbl
    (
    FutureDateTime TIMESTAMP WITH TIME ZONE  default to_timestamp ('2999-12-31 23:23:59.000','yyyy-mm-dd hh24:mi:ss.ff')
    )
    
  • Transpose the timestamp, columns of values in row

    Hello

    I have a table with the values of newspaper of some measures. This table Gets an entry each day, with the date time and only one value for each hour. The table model is something like that,

    Name_EST | Date | VALH1 | VALH2 | .... | VALH24
    Test | 09/01/2011 00:00:00 | 10.8. 5.4 | .... | 14.2

    Where the VALH24 VALH1 represents the value of a measure for each hour (09/01/2011 01:00 to 02/09/2011 00:00:00).

    I would like to know if it is possible to transpose this table so that I can have a diferent entry (row) for each hour, like this:

    Name_EST (Sami). Date | value
    Test | 09/01/2011 01:00 | 10.8
    Test | 09/01/2011 02:00 | 5.4
    Test | 09/02/2011 00:00:00 | 14.2

    I think it's simple to do using a stored procedure, but I would have preferred to make no. using a.

    Thanks in advance.

    Ah, I misread your message.

    Something more like this...

    select name_est
          ,date_col + ((1/24)*rn) as date_col
          ,decode(rn
                 ,1,valh1
                 ,2,valh2
                 ,3,valh3
                 ,4,valh4
                 ,5,valh4
                 ,6,valh4
                 ,7,valh4
                 ,8,valh4
                 ,9,valh4
                 ,10,valh4
                 ,11,valh4
                 ,12,valh4
                 ,13,valh4
                 ,14,valh4
                 ,15,valh4
                 ,16,valh4
                 ,17,valh4
                 ,18,valh4
                 ,19,valh4
                 ,20,valh4
                 ,21,valh4
                 ,22,valh4
                 ,23,valh4
                 ,24,valh4
                 ) as value
    from   tablename
           cross join (select rownum rn from dual connect by rownum <= 24)
    

    BTW. It is not recommended to call your date columns "date" because it is a reserved word.

  • How to compare the unique column values

    Hi all

    I have data in following manner

    PAT_ID PAT_ENC_CSN_ID DEPT_ID EFFECTIVE_DATE

    Z369160557291136405500122 APRIL 14
    Z369160557291136405500222 APRIL 14
    Z269466457982980405500116 MAY 14
    Z269466457982980405500216 MAY 14
    Z268924357987777405500116 MAY 14
    Z268924357987777405500218 MAY 14

    My requirement is to know if the patient changes in another Department at the same time, so I need to select the patient or even dismiss the patient. In my example above, I have to select Z3691605 and Z2694664 patients and ignore the remaining patient.

    Can someone plase help me with the code for that sql. I use 11g.

    Hope I have my question clearly.

    Thank you.

    Here is a way use are:

    SQL > select *.

    2 t a

    3 where exists (select 1

    4t b

    5 where a.pat_id = b.pat_id

    6 and a.pat_enc_csn_id = b.pat_enc_csn_id

    7 and a.effective_date = b.effective_date

    8 and a.dept_id <> b.dept_id

    9                );

    PAT_ID PAT_ENC_CSN_ID DEPT_ID EFFECTIVE_DATE

    ------------------------------ -------------------- -------------------- --------------------

    Z3691605 57291136 4055002 22 APRIL 2014 00:00:00

    Z3691605 57291136 4055001 22 APRIL 2014 00:00:00

    Z2694664 57982980 4055002 16 MAY 2014 00:00:00

    Z2694664 57982980 4055001 16 MAY 2014 00:00:00

  • By comparing the two columns in a datagrid.

    I have a datagrid that has a data provider for some users. Users have a name, address, balance and amount of the payment. For the amount of the payment, I use a custom MXDataItemRenderer like my TextEditor (no text rendering). I want to do is validate that the amount that they are entered in the payment amount does not exceed the balance.

    I tried to do it on an itemEditEndHandler, but the problem is that for some reason that I don't have the amount of payment at this time here. I wonder what I am doing wrong or if I go about it completely the wrong way.

    Any help would be greatly appreciated.

    Thank you

    Here's my editHandler function

    var point: Object = ((event.currentTarget as DataGrid) .dataProvider as ArrayCollection) [event.rowIndex];
    var paymentValidator:PaymentAmountValidator = new PaymentAmountValidator (item.balance);
    paymentValidator.source = this.dataProvider;
    paymentValidator.property = "paymentAmount;
    paymentValidator.validate (item.paymentAmount);

    Here is my custom validator.

    SerializableAttribute public class PaymentAmountValidator extends Validator
    {
    private var: table of results;
    private var scale: Number;
    public void PaymentAmountValidator (balance: Number = 0) {}
    Super();
    This.balance = balance;
    }

    Set the doValidation() method.
    override protected function doValidation(value:Object):Array {}

    Convert the value to a number.
    var inputValue:Number = Number (value);

    Table of clear results.
    results = [];

    Call the base doValidation() class.
    results = super.doValidation (value);
    Back if there are errors.
    If (results.length > 0)
    return results;

    If the input value is not a number, or contains no value,
    issue a validation error.
    If (isNaN (inputValue) |! value)
    {
    Results.push (new ValidationResult (true, null, 'NaN',
    "You must enter an amount."));
    return results;
    }

    If (inputValue > balance) {}
    Results.push (new ValidationResult (true, null, "moreThanBalance",
    "The payment amount must be less than or equal to the balance."));
    return results;
    }

    return results;
    }

    }

    Download the the itemEditorInstance paymentAmount.  It has not been written

    the question still.

  • HELP Please: compare timestamps with excel and make the corresponding value in the next column

    Hello

    I have attached the program I did up to now and the txt file required by the program.

    I want to compare the timestamp given by me at the beginning of the program, and when it is true, I want to take the corresponding value of nearby and use for the calculation.

    I am able to compare the time but I do not know how to take the corresponding '0' or '1' value of the file.

    I'm a beginner to labview. It can be simple, but I couldn't understand it

    Kindly help.

    Thanks in advance

    Arun

    This?  If you get a match, find a true Boolean 1 d array and use the index of the element to get the data of the next column.

  • variable sharing, missing data, the timestamp even for two consecutively given

    Hello

    I have a problem with missing data when I read a published network shared variable.

    Host VI:

    In a host of VI on my laptop (HP with Windows XP Prof.) I write data to the shared Variable 'data '. Between two consecutively write operations is a minimum milliseconds of wait time. I use it because I want to make sure that the time stamp of each new value of data is different then a preview (variables shared the resolution is 1 ms)

    VI target:

    the VI target cRIO-9012 bed only of new data in the way that it compares the timestamp of a new value with the time stamp of the last value on a device in real time.

    Problem:

    rarely, I'm missing a data point (sometimes everything works fine for several hours, transfer thousands of data correctly above all of a sudden failure occurs). With a workaround, I'm able to catch the missing data. I discovered that the missing data have the timestamp exactly the same, then the last point of data read, is so ignored in my data 'legal '.

    To summarize, the missed value is written to the variable shared host, but ignores the target because its timestamp is wrong, respectively the same as the last value, despite the host waits for a minimum of 10 milliseconds each time before writing a new value.

    Note:

    The shared Variable is hosted on the laptop and configured using buffering.

    The example is simple only to display the function of principle, in real time, I also use a handshake and I guarantee that there is no sub - positive and negative.

    Simplified example:

    Question:

    Anyone has an idea why two consecutively data can have the same timestamp?

    Where timestamping (evil) Finally comes (System?)?

    What would be a possible solution (for the moment with shared Variables)?

    -> I tried to work around the problem with the clusters where each data gets a unique ID. It works but it is slower that comparing the timestamps and I could get performance problems.

    It would change anything when I animate the shared on the RT System Variable?

    Thanks for your help

    Concerning

    Reto

    This problem has been resolved in LabVIEW 2010.  You can see other bugs corrections in theReadme of LabVIEW 2010.

  • How to trace the greatness of the variables compared to the timestamp with evenly spaced samples in time?

    Hello world. I need to trace the variable amplitudes compared to the timestamp (date and time), but the time intervals between samples are not equidistant. In my area, this is called trend plot. I'm surprised that Labview does not a vi to do this. The only solution that I found so far is to save the data in an Excel file and open this chart in Excel because it has the ability to trace what that this is against what whatsoever is not limited to something as even spaced samples. How to achieve this is Labview? A graph of waveform vi would be perfect if it was not by the fact that it works with even spaced samples.

    Thank you.

    Paulo Siqueira

    Your requirement is directly possible with LabVIEW.

    You can spend time to understand the difference between 'Chart', 'Graph' and "Graph XY".

    VI attached is drawing samples of unequal time.

    Hint:-right click on the 'XY' graph-> properties-> display-> 'Axis of X' = absolute time Format

    Kind regards

    Yogesh Redemptor

  • How to compare one by an element of a column with the first column in the other table?

    Hello

    I have two files into a single file has only Id numbers and the second file has table with for example the column 4, and his first column identification number.

    So I want to compare the first item in the User.ID file with the 1st column all the table file items in this column until it finds matches.

    If compare match then LED will be IT other wise LED will be OFF.

    Here as an attachment, I've attached the two file.

    Please guide me how can I do the same thing.

    Thank you much in advance.


  • How to compare the different timestamps and check that one is greater.

    Hi guys,.

    I have a small question about datetime.

    I have the following data in a table to the timestamp format.

    01:00:00.000
    19/05/2009

    01:00:00.000
    22/05/2009

    01:00:00.000
    23/05/2009

    What I want to do is to check the date is higher, then the other.  Simply, my question is how to make comparison between dates, especially when they are in the form of time stamp

    Secondly, I would like to ask if I have a timestamp which has the following values

    01:00:00.000
    22/05/2009

    How can I convert in seconds?

    Thank you

    You can create an array of timestamps and min/max table compares sets of stamps.

    Use the double conversion for seconds since...

Maybe you are looking for