Average of the difference in date in minutes

Hi friends

I have a table called attendance with 3 columns
eid  number
in   date
out  date 
two columns (in, out) of date are stored with date and time. The table will have multiple entries
Is it possible that I can calculate the average of the difference in minutes between in and out of all the records
using a single query or don't we have the right to use the loop.
For Example

eid         in                      out             difference in minutes
1    01-01-2012 09:00:00   01-01-2012 10:00:00              60
2    01-01-2012 09:05:00   01-01-2012 10:10:00              65  
3    01-01-2012 09:10:00   01-01-2012 10:20:00              80  
The result should be the average difference of minutes IE (60 + 65 + 80) / 3 which would be 68.33

Thanks in advance
Concerning
Park

Hello

Use

select avg((out - in) * 24 * 60)
from 

Tags: Database

Similar Questions

  • How to find the difference in date in years, months and days

    Hello
    I need to find the difference between 2 dates in the following way "years months days". "
    Please can help me, how can I achieve this.

    for example, in the scott schema emp table, I need to find the difference in date between sysdate and hiredate for an employee in the following way.

    12 years 7 months 4 days.

    Hello

    Please, see this post to AskTom [difference between 2 dates | http://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:96012348060]. There is good information in this forum, for example you can also see this thread [calculation of years, months & days | http://forums.oracle.com/forums/thread.jspa?messageID=3115216�]

    Kind regards

    Published by: Walter Fernández on November 30, 2008 08:58 - adding another link

  • Create lines based on the difference in date

    Hello

    I would like to create lines based on the difference between the start and end dates (per year).

    for example

    ID1  Start_time                                             End_time                                                      ID2
    07/01/2003 1, 12.00.00.000000000 2005-01-07 12.00.00.000000000 123

    07/01/1999 1, 12.00.00.000000000 07/01/2003 12.00.00.000000000 345

    I need:

    ID1  Start_time                                             End_time                                                      ID2
    07/01/2004 1, 12.00.00.000000000 2005-01-07 12.00.00.000000000 123

    07/01/2003 1 12.00.00.000000000 07/01/2004 12.00.00.000000000 123

    1 01/07/2002 12.00.00.000000000 07/01/2003 12.00.00.000000000 345

    07/01/2001 1, 12.00.00.000000000 01/07/2002 12.00.00.000000000 345

    07/01/2000 1, 12.00.00.000000000 01/07/2001 12.00.00.000000000 345

    07/01/1999 1, 12.00.00.000000000 07/01/2000 12.00.00.000000000 345

    Thank you

    Hello

    Here's one way:

    SELECT ID1

    , ADD_MONTHS (start_time, 12 * (LEVEL - 1)) AS start_time value

    , ADD_MONTHS (start_time, 12 * LEVEL) AS end_time

    id2

    FROM table_x

    CONNECT BY LEVEL<= months_between="" (end_time,="" start_time)="">

    AND PRIOR id2 = id2

    AND PRIOR SYS_GUID () IS NOT NULL

    ;

    I'm assuming that id2 is unique.

    Would what results you if end_time wasn't exactly N years after start_time?

  • Unlike COUNTY and the difference in data between 2 sets of data

    Hey guys,.
    I have a question here, probably, it revolves around the UNION, INSERSECT and LESS and maybe something else I'm missing.

    I'm two sets of questions, and I have 2 paintings.
    select count(student_id) from adhoc_student_table1;
    select count(student_id) from adhoc_student_table2;
    
    select student_id from adhoc_student_table1 order by student_id;
    select student_id from adhoc_student_table2 order by student_id;
    These tables contain data and have been sorted by student_id. I want to find the difference in NUMBER between the first set of SELECT and I want to find a difference in the student ID in the second set to SELECT.

    Any ideas? As always, any help is appreciated!

    Hello

    These tables do contain data and have been sorted by student_id. I want to find the difference in COUNT between the first set of SELECT and I want to find a difference in Student IDs in the second set of SELECT.
    

    Hope this helps

    select (select count(student_id) from adhoc_student_table1) -
       (select count(student_id) from adhoc_student_table2) from dual
    
    ---If you want the difference in first table not available in second table.
    
    select student_id from adhoc_student_table1 order by student_id
    minus
    select student_id from adhoc_student_table2 order by student_id
    
    -- or you wanted the difference from both table.
    with tab1 as
    (
       select student_id from
          adhoc_student_table1
    )
    tab2 as
    (
        select student_id from
    adhoc_student_table2
    )
    select * from (select student_id from tab1
                         union select student_id from tab2)
    minus
    select * from (select student_id from tab1
                        intersect select student_id from tab2)
    )
    

    If you could post the input samples and expected, maybe you can get a more valuable solution.

    Concerning
    Anurag Tibrewal.

  • Groovy Script to find the difference between Dates

    I am trying to build a script that takes a date from a RequestField and calculates the number of days between this date and the current date (from session).

    So far, I have a problem, the analysis to-date from the RequestField chain. I found this code but it doesn't seem to work...

    date = new Date().parse('yyyy/MM/dd', '1973/07/09')
    

    I get the following error...

    Error Message: groovy.lang.MissingMethodException: No signature of method: java.util.Date.parse() is applicable for argument types: (java.lang.String, java.lang.String) values: {"yyyy/MM/dd", "1973/07/09"}
    

    Any help would be greatly appreciated.

    Hello

    What version of server? The extract you have here works fine on mine (563).

    This also works for me

    new java.text.SimpleDateFormat('yyyy/MM/dd').parse('1973/07/09')
    

    See you soon

    Nils

  • Calculate the difference of date in milliseconds

    Hi all

    Version:-Oracle Database 10 g Enterprise Edition release 10.2.0.3.0

    Requirement:-to calculate the difference between current systimestamp and January 1, 1970 with milliseconds up to precision (we need this to store in other tables)

    The query I gave below it gives a value of up to 1 sec accuracy

    Select (sysdate - to_date (January 1, 1970 00:00:00 ',' DD-MON-YYYY HH24;)) SS')) * (24 * 60 * 60 * 1000) double;

    Output
    1261545437000

    After 1 second
    1261545439000 and so on

    I can the difference in accuracy to the millisecond
    select (sysdate - to_date('01-JAN-1970','DD-MON-YYYY')) * (24 * 60 * 60 * 1000)+to_number(to_char(systimestamp,'FF3')) from dual;
    

    Max

    Published by: Massimo Ruocchio on December 23, 2009 12:19
    Fix

  • How to calculate daily, hourly average for the very large data set?

    Some_Timestamp

    "Parameter1" Parameter2
    1 JANUARY 2015 02:00. 00:000000 AM - 07:002341.4534676341.4534
    1 JANUARY 2015 02:00. 01:000000 AM - 07:002341.4533676341.3
    1 JANUARY 2015 03:04. 01:000000 PM - 07:005332.3533676341.53
    1 JANUARY 2015 03:00. 01:000046 PM - 07:0023.3436434.4345
    JANUARY 2, 2015 05:06.01:000236 AM - 07:00352.3343543.4353
    JANUARY 2, 2015 09:00. 01:000026 AM - 07:00234.453453.54
    3 FEBRUARY 2015 10:00. 01:000026 PM - 07:003423.3534634.45
    FEBRUARY 4, 2015 11:08. 01:000026 AM - 07:00324.3532534534.53

    We have data as above a table and we want to calculate all the days, the hourly average for large data set (almost 100 million).  Is it possible to use the sql functions of analysis for better performance instead of the ordinary average and group of?  Or any other way better performance?

    Don't know if that works better, but instead of using to_char, you could use trunc. Try something like this:

    select
        trunc(some_timestamp,'DD'),
        avg(parameter1)
    from
       bigtable
    where
       some_timestamp between systimestamp-180 and systimestamp
    group by
       trunc(some_timestamp,'DD');
    

    Hope that helps,

    dhalek

  • How to get the difference in dates in days

    Hi friends,

    How to get the date difference between two dates exactly

    date2-date1 days exactly... shouyld rounded to the nearest value of...

    and one entire display i mean positive integer
    Select round ((sysdate) - to_date (date_start)), date_start days of per_periods_of_service

    This gives negative also result

    Hello

    776317 wrote:
    Hi friends,

    How to get the date difference between two dates exactly

    date2-date1 days exactly... shouyld rounded to the nearest value of...

    Date1 - date2 is the exact number of days is after date2 date1. (It is as accurate as possible, given that the DATEs do not have fractions of a second).

    and one entire display i mean positive integer
    Select round ((sysdate) - to_date (date_start)), date_start days of per_periods_of_service

    You want to probably get the exact number of days first, then ROUND this number:

    SELECT  ROUND (SYSDATE - TO_DATE (date_start, ...))   AS days
    FROM    per_periods_of_service; 
    

    Always pass arguments at least 2 to TO_DATE:
    (1) the string to be converted, and
    (2) a saying string how (1) is formatted

    This gives negative also result

    Right; If date1 is before date2 then date1 - date2 returns a negative number.
    If you want to never get a negative value, use ABS (date2 - date1). If it returns 4, then you know that one of the DATEs was 4 days before the other, but you won't know who was earlier.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

  • How to make the difference between data (different sensors and actuators) is tans/recvd using series com

    Hello

    I get 2 different types of data from the controller. How to differentiate b/w them.

    After receiving my code in deccissions. There are 6 different control elements in my project attached to the controller. Thanks for give me idea how I send data to the controller for this controller to differentiate that exit to be active or low

    First, look at the couple of serial examples that come with LabVIEW. You use the VISA functions to read and write. Your technique to separate the values will work as well in LabVIEW. You would be to convert the string returned by VISA reading to a digital (i.e. with the Scan of the chain). Then do the comparison, then the result of wire to one of the two indicators. Put the terminal of each indicator inside a case statement would be a way to do it.

  • How to get the difference in Date in years, months and days

    Select Sysdate-Birth_date from Employees;
    the query returns the number of days between two dates
    I want to convert this number in years, months and days
    Can someone help me please

    Hoek wrote:
    Try:

    SQL> with t as (
    2  select to_date('01-01-1980', 'dd-mm-yyyy') birthdate
    3  ,      to_date('05-05-2010', 'dd-mm-yyyy') today
    4  from   dual
    5  )
    6  --
    7  --
    8  --
    9  select extract(year from today)-extract(year from birthdate) years
    10  ,      extract(month from today)-extract(month from birthdate) months
    11  ,      extract(day from today)-extract(day from birthdate) days
    12  from   t;
    
    YEARS     MONTHS       DAYS
    ---------- ---------- ----------
    30          4          4
    
    1 row selected.
    

    (May need some adjustments, possibly using the LARGEST, but currently not as long)

    Indeed, a few adjustments...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (
      2    select to_date('31-01-2009', 'dd-mm-yyyy') birthdate
      3    ,      to_date('28-02-2010', 'dd-mm-yyyy') today
      4    from   dual
      5    )
      6  --
      7  --
      8  --
      9  select extract(year from today)-extract(year from birthdate) years
     10  ,      extract(month from today)-extract(month from birthdate) months
     11  ,      extract(day from today)-extract(day from birthdate) days
     12* from   t
    SQL> /
    
         YEARS     MONTHS       DAYS
    ---------- ---------- ----------
             1          1         -3
    
    SQL>
    

    Maybe something like this?

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select to_date('17-nov-2006','dd-mon-yyyy') as c_start_date, to_date('21-jan-2008','dd-mon-yyyy') as c_end_date from dual union all
      2             select to_date('21-nov-2006','dd-mon-yyyy'), to_date('17-feb-2008','dd-mon-yyyy') from dual union all
      3             select to_date('31-jan-2009','dd-mon-yyyy'), to_date('28-feb-2010','dd-mon-yyyy') from dual union all
      4             select to_date('21-jun-2006','dd-mon-yyyy'), to_date('17-jul-2008','dd-mon-yyyy') from dual
      5             )
      6  -- end of test data
      7  select c_start_date, c_end_date
      8        ,trunc(months_between(c_end_date, c_start_date) / 12) as yrs
      9        ,trunc(mod(months_between(c_end_date, c_start_date), 12)) as mnths
     10        ,trunc(c_end_date - add_months(c_start_date, trunc(months_between(c_end_date, c_start_date)))) as dys
     11* from t
    SQL> /
    
    C_START_DATE        C_END_DATE                 YRS      MNTHS        DYS
    ------------------- ------------------- ---------- ---------- ----------
    17/11/2006 00:00:00 21/01/2008 00:00:00          1          2          4
    21/11/2006 00:00:00 17/02/2008 00:00:00          1          2         27
    31/01/2009 00:00:00 28/02/2010 00:00:00          1          1          0
    21/06/2006 00:00:00 17/07/2008 00:00:00          2          0         26
    
  • How to get the difference of two dates in months

    Dear friends,

    I have 4 items on my page.

    2 entered message text (value of loan, monthly deduction)

    2 are message style fields (start date, end date)

    I need to get the difference from above 2 dates in no.. of months. (for example say N)

    So with N, loanvalue should be divided and populated as monthly deduction.

    I tried this way, but not able to get the difference of dates

    {if ("populateMonthlyDeduction". Equals (PageContext.GetParameter (EVENT_PARAM)))}

    System.out.println ("enter populateMonthlyDeduction loop1");

    String xxDeductionStartDate = vo.getCurrentRow ().getAttribute("DeducStartDt").toString ();

    System.out.println ("xxDeductionStartDate is:" + xxDeductionStartDate);

    TXN OADBTransaction = am.getOADBTransaction ();

    java.sql.Date DeductionSDate = null;

    java.sql.Date DeductionEDate = null;

    if(xxDeductionStartDate!=null)

    {

    java.sql.Date startDate = txn.getOANLSServices () .stringToDate (xxDeductionStartDate);

    DeductionSDate = startDate;

    System.out.println ("DeductionSDate is:" + DeductionSDate);

    }

    String xxDeductionEndDate = vo.getCurrentRow ().getAttribute("DedEndDt").toString ();

    if(xxDeductionEndDate!=null)

    {

    java.sql.Date endDate = txn.getOANLSServices () .stringToDate (xxDeductionEndDate);

    DeductionEDate = endDate;

    System.out.println ("DeductionEDate is:" + DeductionEDate);

    }

    int difInDays = xxDeductionEndDate-xxDeductionStartDate; -Please correct me

    How reach it .plz help.

    Thank you

    Aravinda

    I used a custom like this method and calls this method daysBetween PFR.

    I got it. Thanks to you all.

    public int daysBetween(As Date, Date etDate)

    {

    return (int) ((etDate.getTime () - stDate.getTime (()) / (1000 * 60 * 60 * 24));

    }

    If ("populateMonthlyDeduction". Equals (PageContext.GetParameter (EVENT_PARAM)))

    {

    System.out.println ("enter populateMonthlyDeduction loop1");

    String dedStDt = vo.getCurrentRow ().getAttribute("DeducStartDt").toString ();

    String dedEndDt = vo.getCurrentRow ().getAttribute("DedEndDt").toString ();

    If (! dedStDt.Equals (null) &! dedEndDt.equals (null))

    {

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    Date sdate = new Date();

    Date edate = new Date();

    String sdate1 = null;

    String edate1 = null;

    try {}

    sdate = dateFormat.parse (dedStDt);

    EDATE = dateFormat.parse (dedEndDt);

    SimpleDateFormat dateFormat1 = new SimpleDateFormat("dd-MMM-yyyy");

    sdate1 = dateFormat1.format (sdate);

    edate1 = dateFormat1.format (edate);

    int days = daysBetween(sdate, edate);

    int diffInMonths = days/30;

    System.out.println ("days is:" + days);

    System.out.println ("diffInMonths is:" + diffInMonths);

    String sTotValueTuitionFees = vom.getCurrentRow ().getAttribute("TotValueTuitionFees").toString ();//pageContext.getParameter("LoanValue").toString();

    int iTotValueTuitionFees = Integer.parseInt (sTotValueTuitionFees);

    int iMonthlyDeduction = iTotValueTuitionFees/diffInMonths;

    String sMonthlyDeduction = String.valueOf (iMonthlyDeduction);

    System.out.println ("iMonthlyDeduction is:" + sMonthlyDeduction);

    OAMessageStyledTextBean bMonthlyDeduction = (OAMessageStyledTextBean) webBean.findChildRecursive ("MonthlyDeduction");

    bMonthlyDeduction.setValue (pageContext, sMonthlyDeduction);

    }

    catch (ParseException exception) e

    {

    }

    }

    }

  • Difference in date in the same column

    Select to_char (CREATEDON, 'DD-MM-YYYY HH24:MM:SS'), LABSTATUS, history_paperlesstran COMMENTS
    where hnum = ' 797551 order by to_char (CREATEDON, 'DD-MM-YYYY HH24:MM:SS');

    Rownum TO_CHAR(CREATEDON,' LABSTATUS REMARKS)
    ------------------- ---------- --------------------------------------------------
    1 10/20/2010-08:10:08 1 barcode number generated and printed
    2 10/20/2010-08:10:08 1 barcode number generated and printed
    3 10/20/2010-08:10:08 1 barcode number generated and printed
    4 10/20/2010-08:10:08 1 barcode number generated and printed
    5 10/20/2010-08:10:08 1 barcode number generated and printed
    6 10/20/2010-08:10:08 1 barcode number generated and printed
    7 20/10/2010 09:10:55 3 totals received by the Department
    8 10/20/2010-09:10:58 3 totals received by the Department
    9 10/20/2010-09:10:58 3 totals received by the Department
    10 10/20/2010-09:10:58 3 totals received by the Department
    11 20/10/2010 09:10:58 3 totals received by the Department
    12 10/20/2010 10:10:38 3 totals received by the Department
    13 20/10/2010 11:10:34 1 barcode number generated and printed
    14 10/20/2010 11:10:34 1 barcode number generated and printed
    15 20/10/2010 11:10:35 3 totals received by the Department
    16 10/20/2010 12:10:08 3 totals received by the Department
    17 20/10/2010 14:10:03 1 barcode number generated and printed
    18 10/20/2010-14:10:44 3 totals received by the Department

    18 selected lines.

    Dear friends, now I want to get the difference in date on labstatus based, i.e rownum1 - rownum7, rownum2 - rownum8 and rownum17 - rownum18

    Thing is Barcode number generated and printed - totals received at the Ministry for each and every samples.

    Thanks for your solution in advance...

    Published by: bharathit on October 21, 2010 02:18

    You mean something like this?

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select 1 as rn, to_date('20-10-2010 08:10:08', 'DD-MM-YYYY HH24:MI:SS') as dt, 1 as labstatus, 'Barcode number generated and printed' as comments from dual union all
      2             select 2, to_date('20-10-2010 08:10:08','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
      3             select 3, to_date('20-10-2010 08:10:08','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
      4             select 4, to_date('20-10-2010 08:10:08','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
      5             select 5, to_date('20-10-2010 08:10:08','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
      6             select 6, to_date('20-10-2010 08:10:08','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
      7             select 7, to_date('20-10-2010 09:10:55','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
      8             select 8, to_date('20-10-2010 09:10:58','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
      9             select 9, to_date('20-10-2010 09:10:58','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
     10             select 10, to_date('20-10-2010 09:10:58','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
     11             select 11, to_date('20-10-2010 09:10:58','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
     12             select 12, to_date('20-10-2010 10:10:38','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
     13             select 13, to_date('20-10-2010 11:10:34','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
     14             select 14, to_date('20-10-2010 11:10:34','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
     15             select 15, to_date('20-10-2010 11:10:35','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
     16             select 16, to_date('20-10-2010 12:10:08','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
     17             select 17, to_date('20-10-2010 14:10:03','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
     18             select 18, to_date('20-10-2010 14:10:44','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual)
     19  --
     20  -- END OF TEST DATA
     21  --
     22     ,x as (select rn, dt, labstatus, comments, row_number() over (partition by labstatus order by rn) as labrn from t)
     23  --
     24  select y.rn as rn1, y.dt as dt1, z.rn as rn2, z.dt as dt2, round((z.dt - y.dt)*24*60) as mins_diff
     25  from x y join x z on (y.labrn = z.labrn)
     26  where y.labstatus = 1
     27* and   z.labstatus = 3
    SQL> /
    
           RN1 DT1                        RN2 DT2                  MINS_DIFF
    ---------- ------------------- ---------- ------------------- ----------
             1 20/10/2010 08:10:08          7 20/10/2010 09:10:55         61
             2 20/10/2010 08:10:08          8 20/10/2010 09:10:58         61
             3 20/10/2010 08:10:08          9 20/10/2010 09:10:58         61
             4 20/10/2010 08:10:08         10 20/10/2010 09:10:58         61
             5 20/10/2010 08:10:08         11 20/10/2010 09:10:58         61
             6 20/10/2010 08:10:08         12 20/10/2010 10:10:38        121
            13 20/10/2010 11:10:34         15 20/10/2010 11:10:35          0
            14 20/10/2010 11:10:34         16 20/10/2010 12:10:08         60
            17 20/10/2010 14:10:03         18 20/10/2010 14:10:44          1
    
    9 rows selected.
    
    SQL>
    
  • code succcessive to genereate difference between dates in a table

    First create and insert statements;
    create table schedule(iloan_code number , schedule_date date);
    
    insert into schedule values(1001, to_date('01-jun-2012'));
    insert into schedule values(1001, to_date('01-jul-2012'));
    insert into schedule values(1001, to_date('01-aug-2012'));
    insert into schedule values(1001, to_date('01-sep-2012'));
    insert into schedule values(1001, to_date('01-oct-2012'));
    commit;
    The output of the table of the ANNEX should be now like this:
    ILOAN_CODE     SCHEDULE_DATE
    1001              01-JUN-12
    1001              01-JUL-12
    1001              01-AUG-12
    1001              01-SEP-12
    1001              01-OCT-12
    We want an additional column by name as well as the existing columns DAYS that would be the difference between dates.

    First line should be the difference between sysdate as well as the date of June 1, 2012 and successive lines must be the difference between successive calendar date

    For example in the second row the DAYS column should represent the difference between 1 July 2012 and 1 June 2012 and so on for the following ranks too.

    We need get the result by a SELECT statement

    The output of the table in the ANNEX must be something like that.
    iloan_code      schedule_date     days     Logic which we need 
    1001     1-Jun-12     22     sysdate-1st June 2012
    1001     1-Jul-12     30     difference between 1st July 2012 and 1st June 2012
    1001     1-Aug-12     31     difference between 1st aug 2012  and 1st July 2012
    1001     1-Sep-12     31     difference between 1st sep  2012 and 1st aug  2012
    1001     1-Oct-12     30     difference between 1st oct 2012 and 1st sep 2012
    Please notify;

    Hello

    You can change the Hoek solution like this:

    SELECT    iloan_code
    ,             schedule_date
    ,             schedule_date - LAG ( schedule_date
                                , 1
                         , TRUNC (SYSDATE)
                         ) OVER (ORDER BY schedule_date)     AS days_between
    FROM      schedule
    ORDER BY  schedule_date
    ;
    

    If all schedule_dates will be after SYSDATE, then you need not the CASE expression to test if it is.
    The argument optional 3rd to LAG is a return value in case there is no previous line.

    Sri says:
    ... The output of the table in the ANNEX must be something like that.

    iloan_code      schedule_date     days     Logic which we need
    1001     30-Jun-12     07     sysdate-30June 2012
    1001     1-Jul-12     30     difference between 1st July 2012 and 30 June 2012 ...
    

    The difference between 30 June 2012 and July 1, 2012 is not only 1 day?

  • The moving average of the data file

    Hello

    I'm doing a Subvi, which has jumps in the data points.

    The algorithm:

    -build an array of samples (of size round(FPS/2))

    -Take the average

    -subtract the data of the table of average points: = absolute difference (medium-sized data point).

    -compare the difference threshold: If difference > = point, then add 1 to the counter.

    The Subvi (jump detect) is intended to be used in a larger vi, and I need to make sure that it works. But it doesn't now.

    When the vi works and everything is calculated, it does not count the jumps that are visible on the ground.

    Any ideas what I am doing worng?

    Thank you

    The exsist problem in your loop in your Subvi. At this stage you are iterating FPS/2 size of the array, and you only show the last value of all of your calculations. Unless the last value is reported as a jump, it will not be saved. You can easily fix this by putting registers at offset on your loop for, the only question is do something with your Boolean indicator. You can index the Boolean values, and then make a chart or works, but this part is up to you.

  • How to calculate the difference between 2 dates, but with interruptions and stops between

    Hello

    How can I calculate the difference in minutes between 2 dates but taking into account the existence of a table in the Appendix, so if between start_date and end_date arguments, there is no 'work time' then this part of the time will not be included in the total difference.

    Records of the time table example:

    Time_configuration start_hour end_day end_hour
    219:00307:00
    319:00407:00

    so for example first record said that on Monday you start at 19:00 and leave the next day at 7:00 and then save the same sort of thing.

    There is an event that I want to track how many minutes lasted. for example, this event began the day 2 at 19:00 and ended the day 3 at 21:00

    Theoretically, this event really lasted: 840 minutes. This 840 minutes are within the limits of the annex.

    Thanks in advance.

    The storage of the dates not as data type DATE in most cases is bad design. In addition, how do you know what day of the date is 2 at 19:00? East - Monday 2 November 2015 or Monday, March 7, 2016? It is the same for the event. In any case, assuming that both calendar and events don't extend over several weeks:

    According to schedule)
    Select time_configuration 2, 19:00 ' start_hour, end_day 3,' 07:00 ' end_hour of all the double union
    Select 3, 19:00 ', 4,' 07:00 ' double
    ),
    event like)
    Select event_id 1, time_configuration 2, 19:00 ' start_hour, end_day 3: 21:00 ' end_hour of the double
    )
    Select e.event_id,
    Sum)
    less (e.end_day + to_date (e.end_hour, 'HH24'), s.end_day + to_date (s.end_hour, 'hh24:mi')).
    greater (e.start_day + to_date (e.start_hour, 'HH24'), s.start_day + to_date (s.start_hour,'hh24:mi'))))
    ) * 24 * 60 minutes
    Appendix s,
    e event
    where e.start_day + to_date(e.start_hour,'hh24:mi')< s.end_day="" +="">
    and e.end_day + to_date(e.end_hour,'hh24:mi') > s.start_day + to_date(s.start_hour,'hh24:mi')
    E.event_id group
    /

    EVENT_ID MINUTES
    ---------- ----------
    1 840

    SQL >

    SY.

Maybe you are looking for