SQl query to find out time between the different lines of transactions

(See both images from an attachment to get the clear picture of the data and understand the question correctly.)

I have a set of data like this in one of my paintings. (This is a simple representation of the original data.)

Reference table1.jpg

Id        | Type               | Value | Start_date | End_date

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

ZTR0098 | ALLOW | 0 | 1 JUN | 2 JUN |

ZTR0098 | ADTAX | 0 | 1 JUN | 2 JUN |

ZTR0098 | MXTAX | 0 | 1 JUN | 9 JUN |

ZTR0098 | ALLOW | 4. 3 JUN | 15 JUN |

ZTR0098 | ADTAX | 44.00 | 3 JUN | 17-JUNE |

ZTR0098 | MXTAX | 2. 10 JUN | 17-JUNE |

ZTR0098 | ALLOW | 5. 16-JUNE | 20 JUN |

ZTR0098 | ADTAX | 55,34 | 18 JUN | 22 JUN |

ZTR0098 | MXTAX | 1. 18 JUN | 25 JUN |

ZTR0098 | MXTAX | 6. 26 JUN | 31 AUG |

ZTR0098 | ADTAX | 20.09. 23 JUN | 23 JUL |

ZTR0098 | ALLOW | 8. 21 JUN | 31 AUG |

ZTR0098 | ADTAX | 45. 24 JUL | 31 AUG |

each line has a type and a rasthaus id to it. ID belongs to other parent tables. the value of each type is given, and the validity of each value is followed by a field start_date and end_date.

All values start from 1 - JUN and expires on 31 - AUG. Now my requirement is to obtain a report that gives three columns for three different types (ALLOW, ADTAX and MXTAX) with combination of unique values in the effective time interval. Let me put the result below.

Reference table2.jpg

Id         | ALLOW | ADTAX | MXTAX |  Start_date | End_date

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

ZTR0098 | 0 | 0 | 0 | 1 JUN | 2 JUN |

ZTR0098 | 4. 44.00 | 0 | 3 JUN | 9 JUN |

ZTR0098 | 4. 44.00 | 2. 10 JUN | 15 JUN |

ZTR0098 | 5. 44.00 | 2. 16-JUNE | 17-JUNE |

ZTR0098 | 5. 55,34 | 1. 18 JUN | 20 JUN |

ZTR0098 | 8. 55,34 | 1. 21 JUN | 22 JUN |

ZTR0098 | 8. 20.09. 1. 23 JUN | 25 JUN |

ZTR0098 | 8. 20.09. 6. 26 JUN | 23 JUL |

ZTR0098 | 8. 45. 6. 23 JUL | 31 AUG |

As you can see there are no duplicate rows for a combination of (ALLOW, ADTAX and MXTAX) with their respective dates in force. resulting in the above table. the first step is to convert lines to the column which is pretty obvious to do that by grouping on start_date and end_date colum, but the real deal is the time interval during which the combination of the values (ALLOW, ADTAX, and MXTAX) has remained constant.

I wrote under query using Group by.

Select

ID,

NVL (max (decode (type, "ALLOW", value)), 0) as ALLOW

NVL (max (decode (type, 'ADTAX', value)), 0) as ADTAX

NVL (max (decode (type, 'MXTAX', value)), 0) as MXTAX

Start_date,

End_date

from my_table

Group of start_date, end_date, id

start_date, end_date

the results it gives are like this:

Reference table3.jpg

Id       | ALLOW | ADTAX | MXTAX |  Start_date | End_date

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

ZTR0098 | 0 | 0 | 0 | 1 JUN | 2 JUN |

ZTR0098 | 0 | 0 | 2. 1 JUN | 9 JUN |

ZTR0098 | 4. 0 | 0 | 3 JUN | 15 JUN |

ZTR0098 | 0 | 44.00 | 0 | 3 JUN | 17-JUNE |

ZTR0098 | 0 | 0 | 2. 10 JUN | 17-JUNE |

ZTR0098 | 5. 0 | 0 | 16-JUNE | 20 JUN |

ZTR0098 | 0 | 55,34 | 0 | 18 JUN | 22 JUN |

.   .

. .

like wise

but I'm not able to determine the time intervals by using the SQL query.

with

Table1 as

(select the id 'ZTR0098', 'ALLOW' type, 0 val, to_date('1-JUN','dd-MON') start_date, end_date Union to_date('2-JUN','dd-MON') double all the)

Select 'ZTR0098', 'ADTAX', 0, to_date('1-JUN','dd-MON'), to_date('2-JUN','dd-MON') of all the double union

Select 'ZTR0098', 'MXTAX', 0, to_date('1-JUN','dd-MON'), to_date('9-JUN','dd-MON') of all the double union

Select 'ZTR0098', 'ALLOW', 4, to_date('3-JUN','dd-MON'), to_date('15-JUN','dd-MON') of all the double union

Select 'ZTR0098', 'ADTAX', 44.00, to_date('3-JUN','dd-MON'), to_date('17-JUN','dd-MON') of all the double union

Select 'ZTR0098', 'MXTAX', 2, to_date('10-JUN','dd-MON'), to_date('17-JUN','dd-MON') of all the double union

Select 'ZTR0098', 'ALLOW', 5, to_date('16-JUN','dd-MON'), to_date('20-JUN','dd-MON') of all the double union

Select 'ZTR0098', 'ADTAX', 55.34, to_date('18-JUN','dd-MON'), to_date('22-JUN','dd-MON') of all the double union

Select 'ZTR0098', 'MXTAX', 1, to_date('18-JUN','dd-MON'), to_date('25-JUN','dd-MON') of all the double union

Select 'ZTR0098', 'MXTAX', 6, to_date('26-JUN','dd-MON'), to_date('31-AUG','dd-MON') of all the double union

Select 'ZTR0098', 'ADTAX', 20.09, to_date('23-JUN','dd-MON'), to_date('23-JUL','dd-MON') of all the double union

Select 'ZTR0098', 'ALLOW', 8, to_date('21-JUN','dd-MON'), to_date('31-AUG','dd-MON') of all the double union

Select 'ZTR0098', 'ADTAX', 45, to_date('24-JUL','dd-MON'), to_date('31-AUG','dd-MON') of the double

),

days like

(select level - 1 dte + to_date('1-JUN','dd-MON')

of the double

connect by level<= to_date('31-aug','dd-mon')="" -="" to_date('1-jun','dd-mon')="" +="">

)

Select id, allow, adtax, mxtax, min (dte) start_date, max (dte) end_date

(select ID, dte, max (allow) allow, max (adtax) adtax, max (mxtax) mxtax,

ROW_NUMBER() over (order by dte) row_number() - courses (partition by order max (allow), max (adtax), max (mxtax) by dte) gr

go (select id, dte,

-case when type = 'ALLOW' and dte between start_date and end_date then end val 0 otherwise allow.

-case when type = "ADTAX" and dte between start_date and end_date then val 0 otherwise end adtax.

-case when type = "MXTAX" and dte between start_date and end_date then val 0 otherwise end mxtax

Table 1 t,

days d

where d.dte between t.start_date and t.end_date

)

Group by id, dte

)

Group by id, gr, allow, adtax, mxtax

order by id, gr

ID ALLOW ADTAX MXTAX START_DATE END_DATE
ZTR0098 0 0 0 01/06/2015 02/06/2015
ZTR0098 4 44 0 03/06/2015 09/06/2015
ZTR0098 4 44 2 10/06/2015 15/06/2015
ZTR0098 5 44 2 16/06/2015 17/06/2015
ZTR0098 5 55,34 1 18/06/2015 20/06/2015
ZTR0098 8 55,34 1 21/06/2015 22/06/2015
ZTR0098 8 20.09 1 23/06/2015 25/06/2015
ZTR0098 8 20.09 6 26/06/2015 23/07/2015
ZTR0098 8 45 6 24/07/2015 31/08/2015

Concerning

Etbin

Tags: Database

Similar Questions

  • SQL query to find out the version of discoverer

    Hello
    As a developer, is there a query sql DB the dorsal (or script) that can be run on DB to find out the version of Oracle Discoverer installed?
    The query will be different if the discoverer is used with the Oracle Applications (R12.1.3) compared to a Scout running on a plain stand alone Oracle database (Oracle applications not)?

    Thank you
    GG.

    Hello gg

    The VER_NAME and the VER_DESCRIPTION are usually never filled and can be ignnored.

    The VER_RELEASE is the NLY version as you rightly summised. This version is 100% compatible with the discoverer 11g and if you already have it you can go from 10g to 11g without changing anything in the EUL

    VER_MIN_CODE_VER is the minimum version of Oracle Discoverer which can be used with this EUL. In this case, 10.1.2.45.20 is 10g Release 2

    VER_EUL_TIMESTAMP is the date and time, this version of the EUL was published by Oracle - again you can ignore it

    Important fields are VER_RELEASE and VER_MIN_CODE_VER

    Hope this helps
    Best wishes
    Michael

  • How do I know what sql query is taken on time for the concurrent program

    Hi Sir,

    I am running simultaneous program, which takes time to run, I want to know what sql query causing performance

    Thanaks,

    Anthony

    Hi Anthony,.

    Activate the traces on the simultaneous program and then run tkprof on trace file.

    Octavio

  • SQL query to find the total number of source based nonsource passangersbetween source and destination station and passenger station on the same chekindate

    Hello

    SQL query to find the total number of source based nonsource passangersbetween source and destination station and passenger station on the same chekindate.

    Please help on this script and let me know if you need more details.

    ---

    You use a SELECT statement.  Let me know if you need more details.

  • Calculate the elapsed time between the horodateurs log Table

    Hello

    I'm looking for some codes SQL allows to calculate the elapsed time between the timestamps in a log table.  The log table has some STOP-START operations.

    I just want to calculate the elapsed time between the START and PAUSE of Transactions, as well as START and EXECUTE transactions.

    So, in the example below, the time spent must be:

    START 09:15 break 09:20 (5 Minutes)
    START 09:30 to 09:45 (15 Minutes) FULL

    Total elapsed time for LOG_ID 1234 should be 20 minutes.  This excludes the 09:20 at 09:30 BREAK at the START time.

    LOG_ID

    SEQ_NUM

    LOG_TYPE_CD

    CRE_DTTM

    1234

    1

    BEGINNING

    09-15 - 2013:09:15:00

    1234

    2

    BREAK

    09-15 - 2013:09:20:00

    1234

    3

    BEGINNING

    09-15 - 2013:09:30:00

    1234

    4

    ALL THE

    09-15 - 2013:09:45:00

    Any suggestions?

    Thanks for your time

    -DT

    Hello

    Thanks for posting the CREATE TABLE and INSERT.  be sure to post the results desired from these data.

    user13071913 wrote:

    Hi thanks for the help...

    The date is a true timestamp.  ...

    Here's a sample of CREATE TABLE and a few inserts.  3 ID transaction, each with a series of journal entries.

    CREATE TABLE 'LOG_TABLE_X '.

    (SELECT 'ID' CHAR (14 BYTES) NOT NULL,)

    ACTIVATE THE "LOG_TYPE_FLG" TANK (4 BYTES) NOT NULL,

    ALLOW "LOG_DTTM" DATE NOT NULL

    );

    ...

    I'm so confused.  Is log_dttm a TIMESTAMP, you said in the story, or is it a DATE, as you say in the CREATE TABLE statement, or is it a VARCHAR2 as Thur INSERT statements?  I'll assume it's a DATE.

    I left out an important step yesterday.  The computation of the last_start, we need to use a CASE statement so that we record only the time of events STRT.

    Here's the revised query:

    WITH got_last_start AS

    (

    SELECT id, log_type_flg, log_dttm

    LAST_VALUE (CASE

    WHEN log_type_flg = "STRT".

    THEN log_dttm

    END

    IGNORES NULL VALUES

    ) OVER (PARTITION BY id - can - be

    ORDER BY log_dttm

    ) AS last_start

    OF log_table_x

    )

    SELECT id, log_type_flg, log_dttm

    , (log_dttm - last_start) * 24 * 60 elapsed

    , SUM (log_dttm - last_start) OVER (PARTITION BY ID.

    ORDER BY log_dttm

    ) * 24 * 60 AS total_elapsed

    OF got_last_start

    WHERE log_type_flg IN ("CMPT", "PAUS")

    ORDER BY id, log_dttm

    ;

    Output of your sample data:

    ID LOG_ ELAPSED TOTAL_ELAPSED LOG_DTTM

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

    1111 PAUS 09-26 - 2013:09:09:58.17.17

    1111 CMPT 09-26 - 2013:10:09:58 1.00.83

    2222 CMPT 09-26 - 2013:12:09:58 180.00 180.00

    3333 CMPT 09-26 - 2013:10:09:42 59.73 59.73

    In Oracle, when you subtract one DATE from another DATE, the result is the NUMBER of days between them.  In the above query, I multiplied the past columns and total_elapsed by the number of minutes per day (24 * 60), to show the time in minutes.

  • How to measure the difference in time between the passage by zero of a sine wave and the rise time of a pulse on a same graphic?

    I have a sine wave of 50 Hz and a pulse of the signal on the same chart. The difference in phase between the two is between 0-90 degrees.

    Now I need to calculate the time difference between (when the sinusoidal wave passes through zero volts) and (when the pulse increases). The frequency will remain about even for the two signals.

    The request is for a three-phase generator. In simple terms, when the difference in time between the passage to zero of the sine wave and pulse increases increases, it means that the load on the generator has increased.

    I am a novice user of LabView (version 9, 2009), maybe it's a very simple problem but I was pulling on my hair for the past few days and couldn't understand anything. Any help would be greatly appreciated. I use DAQ USB-6008 to measure these tensions and the impulse of the generator and a sensor

    I have attached a jpg file (a graphic that I just did with excel to explain). The time 't' is what I'm trying to measure

    See you soon

    Zdzislaw

    Awais.h,

    For problems of this kind I recommend start writing the granular steps you would take to manually fix this problem.  You can't say LabVIEW (or any programming language) If you can't succinctly describe the solution to your problem.

    The I want to address this problem is to:

    1. find all the zero crossing points and edges on the rise
    2. for every rising edge find the difference between the timestamp and previous passage by zero

    Here is an implementation of this algorithm LabVIEW:

  • query to find space to reduce the point.

    There are storage spaces where the current use is met 90%, and we receive alerts.

    I want to know how much space to add to these storage areas (data files) that use current can be reduced to 80%. or 70%

    Is the any SQL query to find this information.

    database to Oracle 10 g.

    .


    If I have the right to calculation, is perhaps what you are looking for:

    select b.tablespace_name, (b.used_space/b.new_size) * 100 new_used_percent, b.used_percent,
           b.add_size_MB
      from (
            select tablespace_size + (((round(used_percent, 5) - 90)/100) * tablespace_size) new_size,
                   (((round(used_percent, 5) - 90)/100) * tablespace_size) add_size_MB,
                   a.*
              from dba_tablespace_usage_metrics a
           ) b;
    
  • My machine suddenly began to access the internet every few seconds.__How can find out what is the cause? A virus scan led to no result.

    My machine suddenly began to access the internet every few seconds.
    How can I find out what is the cause? A virus scan led to no result.

    Something constantly running must be what actually happen. The network meter gadget shows that it is evenly spaced.

    O.K.  He finds!

    It is McAfee Network Agent - mcnas.exe

    Services of all the MCS crossed and off a
    This one did.

    Don't know if its corrupt or not
    And talk to McAfee is in talks with the India!

    Nothing seems not to be dangerous.

    Thanks again for all the help.

    TREV.

  • What is the interval of time between the virtual machine Linux and ESXi host synchronization?

    I have ESX5.0 with a centos6 installed on this linux virtual machine.

    After the installation of vmware for Linux virtual machine tools, I activated the time synchronization between the virtual machine linux and ESXi host through vmware-toolbox-cmd.

    I wonder what is the interval of time between the virtual machine linux and ESXi host synchronization? If I quickly time OS system, when the OS system time will sync back to the ESXi host?

    According to http://www.vmware.com/files/pdf/techpaper/Timekeeping-In-VirtualMachines.pdf:

    By default, the demon checks the guest only once per minute operating system clock.

    However, depending on whether the guest is behind or in front of the result is different. So, please read the section "periodic synchronization" (at least) in the document mentioned above.

    André

  • What is the difference between the different photo editing programs?

    What is the difference between the different photo editing programs? Photos and lightroom

    Hikristip19200817,

    Greetings.

    Concerning

    Rohit

  • space appears between the 2 lines in the region of the dynamic header.

    Hello

    Could you please suggest me how to remove the space between the 2 lines in the header area.

    In the header section section uses
    <? Call: Header1? >
    <? Appeal: To-tete2? >

    XML tags:
    Header1: <? model: Header1? > <? PARTY_NAME? > <? end model? >
    Tete2:? model: by-tete2? > <? PERIOD? > <? end model? >

    Currently the space appears between the 2 lines in the header area.

    Thank you
    Bhavana

    Hi Jessica,.

    Simply set your model like this:
    Header1:
    Tete2:

    Who would do it. I already checked it and it works.

    See you soon

    Jorge
    p.s if this answers your question please give the points and close the message

  • How can I find several intersect between the number of lines

    Hello

    I created the table as below,

    CREATE TABLE "TRANS" (NUMBER (9.0) "TIDSET", "ITEM" NUMBER (9.0)); "."

    and insert valuse Trans table as below,

    insert into values trans (1,1) insert into values trans (1,3) insert into values trans (1.4); insert into values of trans (1.5); insert into trans values (1.6);
    insert into values trans (2.1); insert into values trans (2.2); insert into values trans (2, 4); insert into values trans (2,6), trans insert values (3,1);
    insert into values trans (3,2) insert into values trans (3.3) insert into values trans (3.6); insert into values trans (1, 2); insert into trans values (1,1);

    and now I have to find the intersection between the lines as below,

    Select tidset from whose point trans = 1
    intersect
    Select tidset in the point transwhere = 2
    intersect
    Select tidset from trans whose point = 3;

    If we have 1000 lines there is no way to find the intersect in this way, so I need to write a program to find the intersect as above without inserting the (item = N) manually each time, can you help me with this please?

    Thank you

    Hello

    user11309581 wrote:
    ... and now I need to find the intersection between the lines as below,

    Select tidset from whose point trans = 1
    intersect
    Select tidset in the point transwhere = 2
    intersect
    Select tidset from trans whose point = 3;

    If we have 1000 lines there is no way to find the intersect in this way,

    This is not true. The query you posted will work well for any number of lines. Perhaps you are really worried about the number of distinct values of the point.

    so I need to write a program to find the intersect as above without inserting the (item = N) manually each time, can you help me with this please?

    In a solution of Ivan, you probably mean "COUNT (DISTINCT point)" rather than "COUNT (*).
    In addition, if element values are predictable, you don't have to code in all hard; You can generate, like this:

    SELECT       tidset
    FROM       trans
    WHERE       item      IN (
                   SELECT     LEVEL
                   FROM     dual
                   CONNECT BY     LEVEL <= n
                 )
    GROUP BY  tidset
    HAVING       COUNT (DISTINCT item)     = n
    ;
    
  • Measure the time between the ridges of the periodic input signal

    We have built a circuit which is supposed to mimic an Exercycle.  We have an IR switch and a spinning wheel, the rccb meets a comparator circuit and the output of the element of comparison, we have running in LabView.  We successfully were able to measure the number of rotations of the wheel and the total distance travelled by the wheel, but are struggling to measure speed.  We cannot find a way to measure the time between picks in real time, which we could then divide the wheel circumference and calculate the speed in real time.  The VI I posted has a square wave simulated rather than the signal we receive on our circuit.  Thanks in advance for the help.

    Jon and David

    I think you're overloading the things trying to get the time between two pulses.  Instead, you can use the VI Express your measures and select frequency for her custom. Then, you can multiply the circumference of the wheel of the frequency to get the speed.

    I hope this helps.

    -Christina

  • 6602 OR time between the redeclenchables task runs

    I'm trying to use a signal level TTL of a device to trigger a train of impulses of the 6602 OR. I have no problem getting the 1st pulse train, but the subsequent pulse trains are delayed and no longer synchronize with new incoming TTL signals. I've tested this with trains of pulses consisting of a pulse with no luck. Is there an interval over time required by a redeclenchables task to "recharge"?

    It might be interesting to note that the initiator of the TTL trigger product the trigger as a 5V increase 0 and can access more than 0.7mA.

    Vadim

    Hi Vadim,

    The trigger must be re-army in a time base tick or two (12, 5-25 ns if you use the time base of 80 MHz) when the previous impulse over, so this probably isn't the issue.

    I expect that you run into is a characteristic of DAQmx how treats the initial delay property for redeclenchables meter tasks.  You can find a description here, but essentially the behavior is to generate a single pulse redeclenchables:

    First start: will stay in a State of rest for the Initial delay, then generate a single pulse of time to the high.

    All of the following triggers: will be remain in a State of rest for the period, and then generate a single pulse of the desired length of top.

    This is true for most of the DAQ hardware.  Recent material (series X, other than the 9172 cDAQ chassis) actually use the behavior waited more than use the initial delay instead some time on each retrigger (with the possibility to go back to the old behavior by setting a property).  On your 6602, my recommendation when generating a single pulse redeclenchables is always set your low time equal to the initial period (the minimum value would be 25 ns).

    Best regards

  • How can I measure the time between the two edges of successive increase, using digital input...

    Hello

    I'm trying to measure the time in seconds between each two successive rising edges on a digital input.

    So far I managed to detect the rising edge, increment a counter at each rising edge and take the time during which the increase is edge

    all I need now is subtract edge currently rising from the previous era of edge rising to calculate (T), which can be 1/frequency and display in real time for the user.

    but I do not know how to do this

    Can someone help me please!

    Note: while I am in a position varies between 200 ms - 2 seconds


Maybe you are looking for