How to calculate the % of time difference between different state

Hi there,
The below query returns the follwoign outptut. I need to calculate the % of time period that a specific state ( state ex: open or closed or all report )exists.
I have to find the time difference between the 2 states . How could I do that ?
The first row shows null for the previous state . How could get actual previous state for the first row?
  SELECT si.station_name,
                vppstation.avi_control_state_code.STATE_SHORT_NAME,
                ash.state_id ,
                lag(ash.state_id) over (order by ash.STATE_EFF_DATE desc) previous_state,
                TO_NUMBER(TO_CHAR(ash.state_eff_date, 'SSSSS')) "periods in sec",
                TO_CHAR(ash.state_eff_date, 'dd-mon-yyyy hh24:mi:ss am') "Date"
           from vppstation.avi_state_history ash
left outer join vppstation.avi_control_state_code
             on ash.state_id = vppstation.avi_control_state_code.state_id
LEFT OUTER JOIN vpproadside.stations_installed si  
             ON ash.station_id = si.station_id               
          where ash.state_eff_date >= to_date('28/02/2010', 'dd/mm/yyyy')
            and ash.state_eff_date <= to_date('03/03/2010', 'dd/mm/yyyy') ;
       group by si.station_name
                     ash.state_id
       order by ash.state_eff_date asc ;
STATION_NAME                   STATE_SHORT_NAME STATE_ID               PREVIOUS_STATE         periods in sec         Date                   
IRDNCST02                      Open             1                    NULL                  85166                  01-mar-2010 23:39:26 pm
IRDNCST02                      All Report       3                      1                      85159                  01-mar-2010 23:39:19 pm
IRDNCMT01                      Closed           2                      3                      81376                  01-mar-2010 22:36:16 pm
IRDNCST02                      Open             1                      2                      78723                  01-mar-2010 21:52:03 pm
IRDNCST02                      All Report       3                      1                      76023                  01-mar-2010 21:07:03 pm
IRDNCMT01                      Open             1                      3                      55922                  01-mar-2010 15:32:02 pm
IRDNCMT01                      Closed           2                      1                      54931                  01-mar-2010 15:15:31 pm
IRDNCHA01                      Closed           2                      2                      41291                  01-mar-2010 11:28:11 am
IRDNCAS01                      Open             1                      2                      38847                  01-mar-2010 10:47:27 am
IRDNCAS01                      All Report       3                      1                      37947                  01-mar-2010 10:32:27 am
IRDNCST02                      Open             1                      3                      35332                  01-mar-2010 09:48:52 am
IRDNCST02                      All Report       3                      1                      32632                  01-mar-2010 09:03:52 am
IRDNCST02                      Open             1                      3                      31502                  01-mar-2010 08:45:02 am
IRDNCST02                      All Report       3                      1                      28802                  01-mar-2010 08:00:02 am
IRDNCHI01                      Open             1                      3                      25368                  01-mar-2010 07:02:48 am
IRDNCHI02                      Open             1                      1                      23939                  01-mar-2010 06:38:59 am
IRDNCMT01                      Open             1                      1                      20696                  01-mar-2010 05:44:56 am
IRDNCCH02                      Open             1                      1                      13452                  01-mar-2010 03:44:12 am
Edited by: Indhu Ram on Mar 11, 2010 1:34 PM
Edited by: Indhu Ram on Mar 11, 2010 2:20 PM

If you look at the table which is output of the given query , there is column called "STATE_ID" It shows the current state ie open or closed or all report.
The column 'PREVIOUS_STATE' shows the state before the current state. .In the table in 2nd row in previous_state column there is state_id = 1 (open)which is the state before 'all report state'

Similar Messages

  • How to calculate the no. of weekdays between two active dates

    Hi all,
    I need to calculate the no. of weekdays between two days.
    For Example:
    If i want to know the number of weekdays between 17-NOV-2008 to 7-DEC-2008 its 10 excluding sat and sun.
    how to do that if the period is more?
    like 1-JAN-2006 to 12-APR-2007
    Thanks in advance..
    Regards,
    Manoj

    NEXT_DAY(start_date - 1,'SUNDAY') is first sunday >= start_date. NEXT_DAY(end_date - 7,'SUNDAY') is last Sunday <= end_date. Therefore:
    (NEXT_DAY(end_date - 7,'SUNDAY') - NEXT_DAY(start_date - 1,'SUNDAY')) / 7 + 1 is number of Sunday's between start_date and end_date. Same way:
    (NEXT_DAY(end_date - 7,'SATURDAY') - NEXT_DAY(start_date - 1,'SATURDAY')) / 7 + 1 As a result, number of weekdays between start_date and end_date is:
    business_day_count := end_date - start_date + 1 -((NEXT_DAY(end_date - 7,'SUNDAY') - NEXT_DAY(start_date - 1,'SUNDAY')) / 7 + 1 + (NEXT_DAY(end_date - 7,'SATURDAY') - NEXT_DAY(start_date - 1,'SATURDAY')) / 7 + 1) or
    business_day_count := end_date - start_date - 1 -(NEXT_DAY(end_date - 7,'SUNDAY') - NEXT_DAY(start_date - 1,'SUNDAY')) / 7 - (NEXT_DAY(end_date - 7,'SATURDAY') - NEXT_DAY(start_date - 1,'SATURDAY')) / 7 or:
    SELECT end_date - start_date - 1 -(NEXT_DAY(end_date - 7,'SUNDAY') - NEXT_DAY(start_date - 1,'SUNDAY')) / 7 - (NEXT_DAY(end_date - 7,'SATURDAY') - NEXT_DAY(start_date - 1,'SATURDAY')) / 7 FROM DUAL; The above code assumes business day count between two dates includes both start and end dates. Keep in mind, the above code is NLS dependent.
    SY.

  • How to tune the query and difference between CBO AND RBO.. Which is good

    Hello Friends,
    Here are some questions I have pls reply back with complete description and url if any ..
    1)How Did you tune Query,
    2)What approach you take to tune query? Do you use Hints?
    3)Where did you tune the query and what are the issue with query?
    4)What is difference between RBO and CBO? where u use RBO and CBO.
    5)Give some information about hash join?
    6) Using explain plan how do u know where the bottle neck in query .. how u will identify where the bottle neck is from explain plan .
    thanks/Kumar

    Hi,
    kumar73 wrote:
    Hello Friends,
    Here are some questions I have pls reply back with complete description and url if any ..
    1)How Did you tune Query, Use EXPLAIN PLAN to see exactly where it is spending its time, and address those areas.
    See the forum FAQ
    SQL and PL/SQL FAQ
    "3. How to improve the performance of my query?"
    2)What approach you take to tune query? Do you use Hints?Hints can help.
    Even more helpful is writing the SQL efficiently (avoiding multiple scans of the same table, filtering early, using built-in rather than user-defined functions, ...), creating and using indexes, and, for large tables, partitioning.
    Table design can have a big impact on performace.
    Look for ways to do part of what you need before the query. This includes denormalizing (when appropriate), the kind of pre-digesting that often takes place in data warehouses, function-based indexes, and, starting in Oracle 11, virtual columns.
    3)Where did you tune the query and what are the issue with query?Either this question is a vague summary of the entire thread, or I don't understand it. Can you re-phrase this part?
    4)What is difference between RBO and CBO? where u use RBO and CBO.Basically, use RBO if you have Oracle 7 or earlier.

  • How bright is the display and difference between MacBook Pro

    I have not decided which MacBook/Pro I will buy. An issue is the display. The display of my old 500Mhz G3 ibook looks quite dim compared to external displays.
    Usual you find the specs for the brightness (eg 300cd/m2) and contrast ratio's (1:800) in the technical data sheets. However, I couln't find this information for the MacBook or MacBook Pro. Does anyone know this values and how do they compare to iMac or the Apple Display (I still have the feeling that external displays are much brighter).
    My second question is, how compares the MaBook display to the MacBook Pro (glossy), besides the different size. I will definite go for a Pro in case the display of the Pro is much better.
    Many thanks
    ibook G3, 500Mhz, 640MByte Ram   Mac OS X (10.4)  

    Hi,
    kumar73 wrote:
    Hello Friends,
    Here are some questions I have pls reply back with complete description and url if any ..
    1)How Did you tune Query, Use EXPLAIN PLAN to see exactly where it is spending its time, and address those areas.
    See the forum FAQ
    SQL and PL/SQL FAQ
    "3. How to improve the performance of my query?"
    2)What approach you take to tune query? Do you use Hints?Hints can help.
    Even more helpful is writing the SQL efficiently (avoiding multiple scans of the same table, filtering early, using built-in rather than user-defined functions, ...), creating and using indexes, and, for large tables, partitioning.
    Table design can have a big impact on performace.
    Look for ways to do part of what you need before the query. This includes denormalizing (when appropriate), the kind of pre-digesting that often takes place in data warehouses, function-based indexes, and, starting in Oracle 11, virtual columns.
    3)Where did you tune the query and what are the issue with query?Either this question is a vague summary of the entire thread, or I don't understand it. Can you re-phrase this part?
    4)What is difference between RBO and CBO? where u use RBO and CBO.Basically, use RBO if you have Oracle 7 or earlier.

  • How to calculate the Processing time for material based on its route ?

    Hello experts,
    I would like to calculate the Scheduled in-house production time based on route.
    Actually this is done in the prod. route in tcode CA02. (via menu Extras => scheduling => schedule).
    After getting the schedule table press the 'scheduling results' button I received the Processing time, Setup and teardown time,... Scheduled in-house production time.
    So I'm looking for a function or any tool to use it in report.
    thanks,
    Eli

    hi,
    from routing screen,extras>scheduling>schedule(give a variant name)>scheduling results>update material master.this writes the info in the temp file.use tcode CA96 to update material master.this updates lot size dependent in house production time in work scheduling view of material master and  deletes the lot size independent inhouse prod, time in MRP2 view.this tool gives more accurate results  for your  inhouse prod. time.
    > Hello experts,
    > I would like to calculate the Scheduled in-house
    > production time based on route.
    > Actually this is done in the prod. route in tcode
    > CA02. (via menu Extras => scheduling => schedule).
    > After getting the schedule table press the
    > 'scheduling results' button I received the Processing
    > time, Setup and teardown time,... Scheduled in-house
    > production time.
    > So I'm looking for a function or any tool to use it
    > in report.
    >
    > thanks,
    > Eli

  • How to Calculate AGE by getting difference between two Date Fields

    HI Gems
    I need to calculate AGE from getting difference from two date fields. But when i am trying to wrte fromula as Current date - date1(some date field) then it is showing error.
    How can i get values.
    Thanks
    Manu

    You already asked this question:
    How to calculate AGE from two different date fields

  • How to calculate the number of months between two string as yyyymm

    Dear all,
    I have two month string like yyyymm e.g. 201003 -- 201105. Now I want to calculate the number of months bertween these two month string? How can I do that? Thanks.

    888099 wrote:
    Hi,
    Hope this will help :
         public static void main(String[] args) {
              Calendar cal1 = new GregorianCalendar(2010, 02, 01);
              Calendar cal2 = new GregorianCalendar(2011, 04, 01);
              int years = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);
              int months = cal1.get(Calendar.MONTH) - cal2.get(Calendar.MONTH);
              System.out.println("number of months : "+Math.abs(years*12 + months));
         }Or with only Strings :
         public static void main(String[] args) {
              String s1 = "201002";
              String s2 = "201104";
              int years = Integer.valueOf(s1.substring(0,4)) - Integer.valueOf(s2.substring(0,4));
              int months = Integer.valueOf(s1.substring(4)) - Integer.valueOf(s2.substring(4));
              System.out.println("number of month : "+Math.abs(years*12 + months));
         }Edited by: 888099 on 28 sept. 2011 05:49Full code solutions will not help the OP, he will be back here with a different Date question. Posters here try to nudge the OP to figure out the solution himself.

  • How to calculate the 99th% times

    I have a set of results for which I need to calculate response times other than the 90th% -- particularly the 99th%, but probably also the 95th% and 99.9th%.
    What options are available for this? The reporting tool seems to calculate only the 90th% -- but since that value is calculated on the fly based on the time filter, the raw data must be available, presumably in the database. Is that schema documented anywhere so that I can pull out the numbers and do the calculation myself? Or is there some other approach?

    Hello
    Yes, you need either to export data from the console to CSV or XLS or go to the database.
    Don't have a documented schema but see this kind of requests:
    -- Report Timers par Steps
    SELECT s.sessionname,
      ch.countername,
      ch.objname,
      ch.instname,
      round(min(cr.counterval),3) "Min",
      round(max(cr.counterval),3) "Max",
      round(avg(cr.counterval),3) "Avg",
      sum(cr.iteration) "Pass",
      sum(cr.errflag*1) "Fail",
      round(stddev(cr.counterval),3) "Std Dev" 
    FROM olt.sessionrun s,
      olt.counterhdr ch,
      olt.counterrun cr
    WHERE s.sessionrunid=ch.sessionrunid
    AND ch.counterhdrid =cr.counterhdrid
    AND ch.countername  = 'Avg Server Time (sec)'
    AND s.sessionname   = '&1'
    AND ch.instname LIKE '[%'
    group by s.sessionname, ch.countername, ch.objname, ch.instname
    ORDER BY s.sessionname, ch.countername, ch.objname, lpad(substr(instname, 2,instr(instname,']')-2), 3,'0')
    JB

  • How to calculate the size of database (a different one)

    Hello Friends,
    I am told to move the data from server to another machine (cloning is one very good option, I agree. But I expect a different answer regarding exports and imports). so How should I go about the task. The destination machine has got unlimited space. So thats not a problem. My questions are :
    1) How should I start the task ( I generally go for studying the structures and their sizes. Is it ok ?)
    2) If I am using Unix machine and there is a limitation that my server will not support file sizes of more than 2 GB, What should I do ?
    3) Shall I have to go for a full database backup or fragment the task ? If I do that , there are many schemas, so it will become tedious. But full backup will exceed OS size limitation. What should be done ?
    4) Is there anyway, I can go through a dump file, to find out, the database objects present inside that and note the related dependencies.
    Please respond.
    Regards,
    Ravi Duvvuri

    1) They are Unix machines. So will the size problem occur(if there is a limitation). How to overcome that?
    If the OS are of the same version you will have any problem. Regarding the storage only you have to have space in disk to store the datafiles, redo logs and controlfiles and nothing else.
    2) I am trying Export/import measure. Though there are other good methods, I just want to explore the full capabilities of Exp/Imp
    r.- Recreate the controlfiles is more effective and fast if the OS are of the same version.
    3) And the oracle version is 9i 2. (If I have to perform this on 8i (both source and destination, will the methods are going to differ ?)).
    R.- The method is the same for 8i/9i/10g.
    How should I go about doing this export/import ?
    r.- To use this method you have to have the original database started.
    To recreate the controlfile without having the datafile that you mentioned you have to get out it from the CREATE CONTROLFILE sentence and that's it.
    For Example: I mean, if your database has 8 datafiles and you have only 7, you have to include only 7 in the CREATE CONTROLFILE sentence.
    Joel Pérez
    http://otn.oracle.com/experts

  • How to calculate the Time difference between 2 dates

    HI All,
    I am using HR_hk_diff_btw_2_dates to calculate the employee service dates.
    For that i  am inputing his hire date and Term dates and Output format as '05' i am getting output perfectly....
    But problem is  whe i am inputting the employee hire date is Dec 1 2007 and Term date is
    March 31 2009 It is coming as 1 year 3 months  31 days instead of 1 year 4 months directly .......How could we make it make last date also working day and get the O/p as 1 year 4 months ?Please Advice..
    Regard
    sas

    1. FM for difference betwwen two times:SCOV_TIME_DIFF
    Import parameters               Value
    IM_DATE1                        2008-01-01
    IM_DATE2                        2008-01-01
    IM_TIME1                        10:00:00
    IM_TIME2                        11:30:00
    Export parameters               Value
    EX_DAYS                         0
    EX_TIME                         01:30:00
    2. SD_CALC_DURATION_FROM_DATETIME : Finds the difference between two date/time and report the difference in hours
    L_MC_TIME_DIFFERENCE : Finds the time difference between two date/time

  • How to calculate the hour difference between two dates?

    hi all,
    how to calculate the hour difference between two dates?
    eg i trying this...
    ((TO_DATE(TO_CHAR(GRNi.reference_date_4,'hh24:mi'),'hh24:mi') -
    TO_DATE(TO_CHAR(NVL(GRNi.reference_date_3,SYSDATE),'hh24:mi'),'hh24:mi'))*24)*60 Act_Hr
    Reg.
    AAK

    Hi
    To break the diff between 2 dates into days, hours, minutes, sec -- you can use the following:
    select to_char( created, 'dd-mon-yyyy hh24:mi:ss' ),
    trunc( sysdate-created ) "Dy",
    trunc( mod( (sysdate-created)*24, 24 ) ) "Hr",
    trunc( mod( (sysdate-created)*24*60, 60 ) ) "Mi",
    trunc( mod( (sysdate-created)*24*60*60, 60 ) ) "Sec",
    to_char( sysdate, 'dd-mon-yyyy hh24:mi:ss' ),
    sysdate-created "Tdy",
    (sysdate-created)*24 "Thr",
    (sysdate-created)*24*60 "Tmi",
    (sysdate-created)*24*60*60 "Tsec"
    from all_users
    where rownum < 50
    HTH
    RangaReddy

  • How to calculate the phase difference between two square wave (acquired from two channel in one DAQ)

    Hello everyone ,
     I need a quickly help that as below :
    I am trying use PCI-6220 to acquired six signals from one rotation encoder (channel A, channel B,channel Z ,and their non-signals) .The encoder out signals will be square wave and 4000pulses per revolution. I set it rotation at 300rpm speed. I need show every square wave of six out channels in waveform and measure the A-B phase difference to check if the value is correct (designed value should be 90deg) .
    I have no idea how to measure or calculate the phase difference of two square wave base on synchronizate to acquire these two square wave from two channel on the PCI-6620....
    Anyone can give a idea how to calculate the phase difference with two square wave ?
    Thank a lot and Thanks again...
    Tim

    Tim,
    Here is a simple rising edge detector for one channel.
    Lynn
    Attachments:
    Rising edge.vi ‏15 KB

  • How can I measure the time difference between spikes (interspik​e intervals)

    I have used NI USB-6008 (DAQ) to sample a continous signal, after sampling I compared the amplitude of the resulted signal with a value. If the amplitude is greater than a specific value (threshold) then it can pass. Now I want to measure the time difference between the resulted samples. The samples look like spikes. (May be if I trigger a timer, then I can measuer the time difference, but I have not seen such a timer). 
    Thanks in advance,
    Saraydin

    Oops just occured to me that you are using a 6009 which is not very fast, 48ks/sec, this will not get you very much time resolution and you could have issues seeing much of a 50 us sample.  Another approach is to use the counter but you would have to preprocess the spikes to generate a trigger for the counter.
    Paul
    Paul Falkenstein
    Coleman Technologies Inc.
    CLA, CPI, AIA-Vision
    Labview 4.0- 2013, RT, Vision, FPGA

  • How to calculate the time between start trigger,first scan and first A/D in DAQ

    Environment: Labview 6.1, N6052E DAQ board(max scan rate=333KHz, max channel rate=333KHz, settling time=3.5usec+1LSB)
    I am using external scan clock 10K scan/s collecting data on 16 AI channels, and external channel clock 200KHz.
    Could show me how to calculate the time betweent he start trigger, the first scan and the first A/D conversion?
    Thanks

    I read the one you give to me. still cannot work out. I am using Labview 6.1 DAQ vi, including AI config.vi. clock config.vi, AI control.vi, AI read.vi, working on colect data on 16 AI channels. So I belong to SCAN function and external scan and sampling timing, right?
    But it says the T1 and T2 are determined by external signals. How can I calculate that?
    T1=1/10KHz or T1=1/160Khz?
    T2=1/200KHz?
    Is the above correct?

  • How to Calculate the Time Between two days in ABAP

    Hi,
                  I have one scenario like i need to calculate the time between two days please can you suggest me.
    Thanks,
    Harinath

    Hi Peeleti,
                Check this code,
    DATA : DATE1 LIKE SY-DATUM VALUE '19830125',
           DATE2 LIKE SY-DATUM VALUE '20070219',
           DAYS1 TYPE I,
           WEEK1 TYPE I,
           MONTH1 TYPE I,
           YEAR1 TYPE I,
           C_YEARS1 TYPE I.
    CALL FUNCTION 'HR_99S_INTERVAL_BETWEEN_DATES'
    EXPORTING
      BEGDA           = DATE1
       endda           = DATE2
      TAB_MODE        = ' '
    IMPORTING
      DAYS            = DAYS1
      C_WEEKS         =
      C_MONTHS        = C_YEARS1
      C_YEARS         = C_YEARS1
      WEEKS           = WEEK1
      MONTHS          = MONTH1
      YEARS           = YEAR1.
      D_MONTHS        =
      MONTH_TAB       =
    *WRITE : / 'DAYS   = ', DAYS1,
            / 'WEEKS = ',WEEK1,
          /  'MONTHS = ', MONTH1,
          / 'YEARS   = ', YEAR1.
    Using this code you can calculate the No Of Days Between two dates. Based On days you will easily calculate the Hour. [  No of days * 24 ].
    Thanks.
    Reward If helpful.

Maybe you are looking for

  • SharePoint 2013 and SQL Server 2012

    Hi all,  I've looked around and not found a concrete answer to this question; or maybe I have and just haven't realised! Anyway. We've currently got a license for SharePoint 2013 Enterprise, and are working on introducing Business Intelligence capabi

  • Problem with calcule in SD conditions

    Hello! I´ve been created a new formula in VOFM>Formulas>Condition values. In my include RV, i have this code: data: v_value type p decimals 6. Select * from konp into wa_konp.... v_value = wa_konp-kbetr / wa_konp-kpein. Variables values are: wa_konp-

  • Volume Levels in Logic?

    OK, this problem has been baffling me for two days now... MacBook Pro, Logic 9.1.7, Lion OSX 10.7.4, MOTU Traveler mk3 + MOTU 8Pre - firmware is up to date, CueMix is up to date (1.6) Recording levels of Audio tracks in Logic don't go past about 20%.

  • Error in LSMW for ME51N

    Hello, I'm working with the BAPI option of the LSMW using BUS2105 method CREATEFROMDATA1 as is said in  When I'm processing the IDoc the following error is showed: "Please enter items first" When I upload the files the asignation of the fields is cor

  • Batch merging of Video+Audio with QT Pro 7?

    Hello. Wondering if anyone could help me out on an issue i'm having please. I'm using Quicktime Pro 7, and want to combine 50+ audio tracks with corresponding video tracks. I know about how you can combine/merge video & audio in Quicktime. This featu