Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help with PL/SQL

turnerkturnerk Member Posts: 5
TAG Timestamp Value
XXX1 12-MAR-2003 16:00 0
XXX2 12-MAR-2003 16:01 0
XXX3 12-MAR-2003 16:02 1
XXX4 12-MAR-2003 16:03 0
XXX5 12-MAR-2003 16:08 1
XXX5 12-MAR-2003 16:09 0

I need just to pull the values like this when 1 changes to 0.

Timein Time_Out
12-MAR-2003 16:02 12-MAR-2003 16:03
12-MAR-2003 16:08 12-MAR-2003 16:09

Thanks in Advance.


Comments

  • infidelinfidel Member Posts: 2,900
    : TAG Timestamp Value
    : XXX1 12-MAR-2003 16:00 0
    : XXX2 12-MAR-2003 16:01 0
    : XXX3 12-MAR-2003 16:02 1
    : XXX4 12-MAR-2003 16:03 0
    : XXX5 12-MAR-2003 16:08 1
    : XXX5 12-MAR-2003 16:09 0
    :
    : I need just to pull the values like this when 1 changes to 0.
    :
    : Timein Time_Out
    : 12-MAR-2003 16:02 12-MAR-2003 16:03
    : 12-MAR-2003 16:08 12-MAR-2003 16:09

    This is just a guess (I haven't tested it):

    [code]
    select in.Timestamp as Time_In, out.Timestamp as Time_Out
    from times in, times out
    where out.Timestamp = (select min(Timestamp) from times t
    where t.Timestamp > in.Timestamp)
    and in.Value = 1
    and out.Value = 0
    [/code]

    I don't know if joining a table to itself like this is the most efficient way, but this seemed like the easiest answer. Assuming it works.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

Sign In or Register to comment.