summarize records by date range

I have an ambitious project where I need to report a summary report for a date range for each code. I'm not against the use of a helper function plsql to calculate the summary result because I'm not sure it can be done in sql. Any help would be appreciated as my attempts have failed.

Here is a sample of the data.

ID START_DATE END_DATE
445 1 January 2010 Thursday, April 30, 2010 - simultaneous example
445 1 JANUARY 2010 MAY 31, 2010
445 17 MAY 2010 AUGUST 6, 2010
2710 1 May 2010 August 31, 2010 - row example
2710 01 - SEP - 2010 DECEMBER 31, 2010
2710 1 JANUARY 2011 APRIL 30, 2011
2710 1 MAY 2011 AUGUST 31, 2011
658 1 January 2010 Thursday, April 30, 2010 - simultaneous example
658 1 JANUARY 2010 MAY 31, 2010
658 1 JANUARY 2010 MAY 31, 2010
108 28 December 2009 January 22, 2010 - non-consecutive example
108, 29 MARCH 2010 APRIL 11, 2010
108. ON MAY 1, 2010 MAY 31, 2010
2535 1 March 2010 March 14, 2010 - example 2 consecutive and non-consecutive 1 combination
2535, MARCH 15, 2010 MARCH 28, 2010
2535, APRIL 5, 2010 MAY 2, 2010
999 1 March 2010 March 14, 2010 - example 2 simultaneous and consecutive 1 combination
999, 1 MARCH 2010 APRIL 24, 2010
999 APRIL 25, 2010 MAY 2, 2010


Here is the result summary of what I would be returned as for each ID

ID START_DATE END_DATE
445 1 JANUARY 2010 AUGUST 6, 2010
2710 1 MAY 2010 31 AUGUST 2011
658 1 JANUARY 2010 MAY 31, 2010
108. ON MAY 1, 2010 MAY 31, 2010
2535, APRIL 5, 2010 MAY 2, 2010
999, MARCH 1, 2010 MAY 2, 2010

Thank you
Todd

Hello

I see it; you want to look at only the last set of overlapping lines for each id, where the definition of "overlap" is extended such that two rows are expected to overlap if the line later begins between 0 and 24 hours after the end of the previous.

So what I posted was a bit off; Need to add a WHERE clause to not take into account that the last series of overlapping lines. Which would be to change the FROM clause to use, not the table, but something that indicates whether a line is in the last together or not, and this is the interesting part. We can use analytical functions (I used MIN in the example below) to determine if a game begins with a certain rank, then we can use other analytical functions (such as SUM) to see how many series began, and therefore, what game of any line belongs.

WITH  got_new_grp     AS
(
     SELECT     id, start_date, end_date
     ,     CASE
              WHEN  end_date     < MIN (start_date) OVER ( PARTITION BY  id
                                                         ORDER BY       start_date
                                          ROWS BETWEEN     1        FOLLOWING
                                               AND     UNBOUNDED  FOLLOWING
                                        ) - 1
              THEN  1
              ELSE  0
          END     AS new_grp
     FROM    my_data
)
,     got_grp          AS
(
     SELECT     id, start_date, end_date
     ,     SUM (new_grp) OVER ( PARTITION BY  id
                                   ORDER BY          start_date     DESC
                       )         AS grp
     FROM     got_new_grp
)
SELECT       id
,       MIN (start_date)     AS start_date
,       MAX (end_date)     AS end_date
FROM       got_grp
WHERE       grp     = 0
GROUP BY  id
ORDER BY  id
;

Output of your sample data:

.       ID START_DATE  END_DATE
---------- ----------- -----------
       108 01-May-2010 31-May-2010
       445 01-Jan-2010 06-Aug-2010
       658 01-Jan-2010 31-May-2010
       999 01-Mar-2010 02-May-2010
      2535 05-Apr-2010 02-May-2010
      2710 01-May-2010 31-Aug-2011

Given that this problem is the last set of rows for each id, I counted sets in order from the last to the first.
I consider a row of "from" a group if she finished more than 24 hours before all the lines that begin beginning later. Subquery got_new_grp sets new_grp to 1 for these lines. new_grp is 0 for all lines that overlap with a few lines later departure.

Published by: Frank Kulash, June 11, 2010 12:30

Tags: Database

Similar Questions

  • Get number of records in the date range - IDE: PLSQL Developer

    I want to count the number of records of members who register within a date range specified, based on effective and expiration dates and their "elg_code". I posted the SQL code for some examples of data. What I would like to see returned is in three columns of the counties where the eff_date date_exp members fall within the date range specified by the SQL and have an Elg_code of ' ' (space).

    So what I would like is all members with elg_code ' ' where he eff_dt and exp_dt range is April 2012, 2012 MAY & JUN 2012. Thus, according to data from the sample I posted, Mark, where his elg_code record is ' ', his eff_dt is 01/01/2011 and April 2012 (30/04/2012) is his exp_dt. Range of the brand statement may 2012, but not MAY or JUNE of 2012. Marty would tally for the APR and MAY because his eff_dt is before MAY 2012 and his exp to MAY 2012. etc...

    According to the data below, the results should resemble:

    APR MAY JUN
    4-3-2

    APR should have FRANK, MARK, MARTY, MARY.
    MAY should have FRANK, MARTY, MARY
    JUN should have FRANK and MARIE

    NOAM and JOHN should not appear as his records with elg_code ' ' have no documents eff_dt and exp_dt which are April-June 2012.

    So what I tried without success as it appears that I have a kind of Cartesian question (?), is:

    Select count (m1.mbr_name) APR,
    Count (m2.mbr_name) MAY,
    Count (m3.mbr_name) JUN
    mbr2 M1,
    mbr2 m2,
    mbr2 m3
    "where m1.eff_dt < ' 01 - may - 2012"
    "and m1.exp_dt > ' 01-Apr-2012.
    and m1.elg_code = ' '
    "and m2.eff_dt < 1 June 2012"
    "and m2.exp_dt > ' 01 - may - 2012"
    and m2.elg_code = ' '
    "and m3.eff_dt < 1 July 2012"
    "and m3.exp_dt > 1 June 2012"
    and m3.elg_code = ' '


    Here's the DML

    Thanks for any help!


    create table mbr2 (mbr_name varchar (10), varchar (1) grpid eff_dt date, date of exp_dt elg_code varchar (1))
    Commit

    insert into mbr2 values ('BRAND', 'A', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (April 30, 2012 ',' DD-MM-YYYY '), ' ')
    insert into mbr2 values ('BRAND', 'A', to_date (May 1, 2012 ',' DD-MM-YYYY '), to_date (31 December 2013 ',' DD-MM-YYYY '), 'C')

    insert into mbr2 values ('MARTY', 'A', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (May 31, 2012 ',' DD-MM-YYYY '), ' ')
    insert into mbr2 values ('MARTY', 'A', to_date (June 1, 2012 ',' DD-MM-YYYY '), to_date (31 December 2013 ',' DD-MM-YYYY '), 'C')

    insert into mbr2 values ('FRANK', 'B', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (June 30, 2012 ',' DD-MM-YYYY '), ' ')
    insert into mbr2 values ('FRANK', 'B', to_date (July 1, 2012 ',' DD-MM-YYYY '), to_date (31 December 2013 ',' DD-MM-YYYY ""), 'C')

    insert into mbr2 values ('MARY', 'B', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (June 30, 2012 ',' DD-MM-YYYY '), ' ')
    insert into mbr2 values ('MARY', 'B', to_date (July 1, 2012 ',' DD-MM-YYYY '), to_date (31 December 2013 ',' DD-MM-YYYY ""), 'C')

    insert into mbr2 values ('JOHN', 'C', to_date (January 1, 2011 ',' DD-MM-YYYY '), to_date (July 1, 2011 ',' DD-MM-YYYY '), ' ')
    insert into mbr2 values ('JOHN', 'C', to_date (July 1, 2011 ',' DD-MM-YYYY '), to_date (1 January 2012 ',' DD-MM-YYYY ""), 'C')

    insert into mbr2 values ("NOAM" 'd', to_date (July 1, 2012 ',' DD-MM-YYYY '), to_date (31 December 2013 ',' DD-MM-YYYY '), ' ' ")

    Commit

    This gives you a report for the current month and the two front. Column header must be adjusted ;-)

    select
      count(
      case
      when
        eff_dt < add_months(trunc(sysdate,'MM'), -1)
        and
        exp_dt >= add_months(trunc(sysdate,'MM'), -2)
      then 1
      end) April
    , count(
      case
      when
        eff_dt < add_months(trunc(sysdate,'MM'), 0)
        and
        exp_dt >= add_months(trunc(sysdate,'MM'), -1)
      then 1
      end) May
    , count(
      case
      when
        eff_dt < add_months(trunc(sysdate,'MM'), 1)
        and
        exp_dt >= add_months(trunc(sysdate,'MM'), 0)
      then 1
      end) June
    from mbr2
    where
    elg_code = ' '
    and
    eff_dt < add_months(trunc(sysdate,'MM'), 1)
    and
    exp_dt >= add_months(trunc(sysdate,'MM'), -2)
    
    APRIL     MAY     JUNE
    4     3     2
    
  • SQL help on records in the range of dates in a month

    Hello

    I have a simple requirement on Sql.

    I have two records in the table of the absence-

    Absence1 January 6, 2015 at 10 January 2015, 5 days

    Absecne2 January 21, 2015 to 31 January 2015, 11 days

    I need to write a Sql to get all the records separate date, as under-

    January 5, 2015, 1 January 2015 days 5 days

    January 6, 2015 at 10 January 2015 5 days of absence

    January 20, 2015, 11 January 2015 10 days working days

    January 21, 2015 to 31 January 2015, 11 days of absence

    Could be for any month, I just have absences stored in a table and will pass the dates of beginning and end of the month.

    I can write this in Pl/Sql, but wanted to see if it's possible in Sql.

    TIA

    Vignesh

    Here's a way to do it.

    with the days as

    (select mstart + lv mdate

    Of

    (select mstart to_date('201501','yyyymm')-1, lv)

    of the double

    cross join

    (select level lv

    of the double

    connect by level<=>

    )

    )

    )

    abs as

    (select 1 anum, to_date ('20150106', 'YYYYMMDD') date_from, to_date ('20150110', 'YYYYMMDD') date_to, 5 days_abs of all double union)

    Select option 2, 5 days_abs of the double to_date ('20150121', 'YYYYMMDD') from_date, to_date ('20150131', 'YYYYMMDD')

    )

    --

    Select min (mdate) date_from, max (mdate) date_to, max (day_type) day_type

    Of

    (select mdate, where anum is null then 'working days' else 'Absence' end day_type, max (rn) on rn (order by mdate))

    Of

    (select mdate, anum, case when row_number() over (order by mdate) = 1 or nvl(anum,0) <> (nvl(anum,0)) (order of mdate) lag then row_number() (any order by mdate) end rn)

    Of

    (select mdate, anum)

    days d

    join left abs one on d.mdate between a.date_from and a.date_to

    )

    )

    )

    Group by rn

    date_from order;

  • To add totals in a certain date range

    I have 3 sheets. Income, expenses and then an annual journal (has twelve columns, one for each month). Is there a way to get the numbers to add totals to a column of the spreadsheet of spending within the date range 01/01/16 and 31/01/16 and put the total in a cell in January on my sheet of each year. I can't understand a formula so that it can find the date range. I get a synyax error message.

    Assumptions:

    Your TABLES (not the leaves) are named income, spending and summary. Here is any other tables in the document with these names.

    Dates of expenditure are in column A of the table expenses. Other than the header line, all the entries in this column are values Date and time that have been entered as dates only.

    The amount for each item of expenditure is in column C of the expense table.

    Line 1 of the analytical table is defined as a header line.

    January is in column A of the summary table.

    Summary::A1 cell contains the date January 1, 2016, but can be formatted to display only the name of the month or the month and year. (but see the note below) *.

    Enter the formula in the cell that will contain total expenditures recorded with dates in January 2016 below:

    = SUMIFS ("Expenses: Expenses, $C: $A," > = "& A1, Expenses: $A," < = "& EOMONTH(A1,0))

    Example: All the amounts of expenditure were reduced to 1.00 simple confirmation of funds.

    * NOTE: The formula has previously worked with the format of the cells in the row 1 Summary defined to show only the month and the year (two digits) of the effective date values (the first day of the month indicated), but the table I built tonight January 1, 2015 to the format to display 16 Jan, one was interpreted as January 16 (2016) , and SUMIFS formula did not include not January 1 to January 14 numbers in January total.

    A custom, displaying the month (short or long) and the year (four digits) or a custom format shows only the name of the month (short or long) gave good results.

    Note that any format under control of the display, the effective date is the first of the month displayed.

    Table built and tested in Numbers ' 09 (v 2.3)

    Kind regards

    Barry

  • GROUP BY date range to identify duplicates revisited!

    Good afternoon

    It is a continuation of the previous discussion, I previously created GROUP BY date range to identify duplicates

    Your help with the following would be appreciated (examples of data below)

    I've highlighted what I mark as returned to double as below:

    example4.jpg

    Definition of duplicate (However, this is slightly different to the previous post)

    the same account_num

    maximum 20 days apart tran_effective_date

    tran_processed_date maximum 10 days apart

    the same tran_amount

    However, I do not want to return a duplicate if they have both a tran_priced_date filled.

    So, in light of the foregoing, I don't expect the following account_numbers to be marked as duplicate:

    N100283 - one of the records has populated trab_priced_date

    N101640 - none of the records have the tran_priced_date filled

    N102395 - same as N101640

    N102827 - same as N101640

    N108876 - although the two documents have the populated tran_priced_date, the tran_effective_dates are more than 20 days apart.

    BUT for the rest of the accounts, N100284 and N102396 I want to execute the following logic

    Compare the 3rd rank in 4th place and ask the following questions:

    Is tran_effective_date to a maximum of 20 days out?

    Is tran_processed_date maximum 10 days apart?

    If yes then report it as dupe

    Compare line 4 to 5, then ask the same question until you get to the line 4 or 5. When everything is done, I want to examine only the transactions that have the status of normal and if the above question is true for both and then return to my game of result as dupes.

    I hope that makes sense!

    BEGIN
      EXECUTE IMMEDIATE 'DROP TABLE samp_data';
    EXCEPTION
      WHEN OTHERS THEN
        IF SQLCODE = -942 THEN
          DBMS_OUTPUT.put_line('');
        ELSE
          RAISE;
        END IF;
    END;
    /
    
    
    CREATE TABLE samp_data (
      ACCOUNT_NUM             VARCHAR2(17),
      TRAN_ID                 NUMBER(10),
      TRAN_TYPE               VARCHAR2(50),
      TRAN_EFFECTIVE_DATE     TIMESTAMP(6),
      TRAN_PROCESSED_DATE     TIMESTAMP(6),
      TRAN_STATUS             VARCHAR2(17),
      TRAN_PRICED_DATE        TIMESTAMP(6),
      TRAN_AMOUNT             NUMBER(13,2)
      );
    /
    
    
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N100283',140119178,'Regular With',to_timestamp('01-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('22-MAY-15 07.00.34.235000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', to_timestamp('21-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),200);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE,TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N100283',140158525,'Regular With',to_timestamp('13-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('26-MAY-15 08.39.14.090000000 AM','DD-MON-RR HH.MI.SS.FF AM'),'Normal', null,200);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N100284',140118826,'Regular With',to_timestamp('03-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('22-MAY-15 07.00.19.072000000 AM','DD-MON-RR HH.MI.SS.FF AM'),'Normal', to_timestamp('20-MAY-15 03.25.05.438000000 AM','DD-MON-RR HH.MI.SS.FF AM'),450);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N100284',140158120,'Regular With',to_timestamp('06-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('23-MAY-15 08.38.42.064000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Reversed', to_timestamp('21-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),450);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N100284',140158120,'Regular With',to_timestamp('06-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('02-JUN-15 08.38.42.064000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', to_timestamp('31-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),450);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N101640',140118957,'Regular With',to_timestamp('18-MAY-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('22-MAY-15 07.00.25.015000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', null,120);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N101640',140158278,'Regular With',to_timestamp('22-MAY-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('26-MAY-15 08.38.56.228000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', null,130);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N102395',140118842,'Regular With',to_timestamp('03-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('22-MAY-15 07.00.19.665000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', null,250);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N102395',140158235,'Regular With',to_timestamp('03-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('26-MAY-15 08.38.53.093000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', null,250);
    
    
    
    
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N102396',140118823,'Regular With',to_timestamp('09-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('18-MAY-15 07.00.18.931000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', to_timestamp('19-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),750);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N102396',140158099,'Regular With',to_timestamp('16-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('24-MAY-15 08.38.39.443000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Reversed', to_timestamp('21-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),750);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N102396',140158099,'Regular With',to_timestamp('16-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('29-MAY-15 08.38.39.443000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', to_timestamp('30-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),750);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N102396',140158099,'Regular With',to_timestamp('12-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('22-MAY-15 08.38.39.443000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Reversed', to_timestamp('30-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),750);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N102396',140158099,'Regular With',to_timestamp('14-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('23-MAY-15 08.38.39.443000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Reversed', to_timestamp('30-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),750);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N102827',140118850,'Regular With',to_timestamp('03-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('22-MAY-15 07.00.20.045000000 AM','DD-MON-RR HH.MI.SS.FF AM') , 'Normal',null,157.84);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N102827',140158118,'Regular With',to_timestamp('03-JUN-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('26-MAY-15 08.38.41.861000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', null,157.84);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N108876',139840720,'Regular With',to_timestamp('01-MAY-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('11-MAY-15 08.35.34.646000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', to_timestamp('20-MAY-15 03.25.05.438000000 AM','DD-MON-RR HH.MI.SS.FF AM'),1000);
    Insert into samp_data (ACCOUNT_NUM,TRAN_ID,TRAN_TYPE,TRAN_EFFECTIVE_DATE,TRAN_PROCESSED_DATE, TRAN_STATUS, TRAN_PRICED_DATE,TRAN_AMOUNT) 
    values ('N108876',139889880,'Regular With',to_timestamp('22-MAY-15 12.00.00.000000000 AM','DD-MON-RR HH.MI.SS.FF AM'),to_timestamp('12-MAY-15 08.49.29.080000000 AM','DD-MON-RR HH.MI.SS.FF AM'), 'Normal', to_timestamp('21-MAY-15 03.26.18.954000000 AM','DD-MON-RR HH.MI.SS.FF AM'),1000);
    /
    
    
    select * from samp_data
    ORDER BY account_num, tran_effective_date, tran_processed_date;
    

    PL continue the discussion in your original post

  • Date range - CM14 and BI Publisher

    I have already asked on a date range. I have a follow-up question. Is it possible to set a range of dates in a form and not a report?

    To add the date range in the header of the form/report, you will first need to modify the data model so that you have a floor/ceiling or min/max output value.  This allows to retrieve the records name and which were added after the user enters the prompt.  Technically it does NOT display what the user types in, but rather the first and the last date in the accounts made within the range.

    I don't think there is a way to add the dates entered in the prompt on the release of the report.

    Then, to add to a form.  I have not tested the guest with forms but thanks to explain what you wanted.  First of all, if you set the prompt for CRITERIA in the form on the Date of receipt of the material, you can test to see if it recovers the correct records.  If the CRITERIA function does not recover on the form, then it is possible that the Oracle only built this based on criteria to work on the reports.  If it works, you must add additional expressions in the data model to retrieve the first and last records to display the 'to' and 'from' dates on the form.

    Otherwise, your solution to ask for dates and material_name in the report is the next best thing.

  • Date range search

    Hello
    Filtering data for a specific date range does not give the desired result. Currently, the column is a column varchar2.

    Then under query should display the records only 2 for the range of data between 01/01/2013, but his displays all records. Please notify.

    Sample data:


    create table Records_test (B_Recorded_Date VARCHAR2 (4000 BYTE))

    insert into Records_test values('12/04/2013');
    insert into Records_test values('7/25/2000');
    insert into Records_test values('10/30/2003');
    insert into Records_test values('9/5/2006');
    insert into Records_test values('12/5/1994');
    insert into Records_test values('12/19/2013');
    insert into Records_test values('9/4/1992');
    insert into Records_test values('8/7/2007');
    insert into Records_test values('9/28/2005');
    insert into Records_test values('12/10/2004');
    insert into Records_test values('11/28/2011');

    Select * from Records_test
    where
    (
    TO_CHAR (TO_date (substr (B_Recorded_Date, 0, 10), ' MM/DD/YYYY'), ' MM/DD/YYYY') > = to_char (to_date('07/01/2013','MM/DD/YYYY'), ' MM/DD/YYYY')
    and to_char (TO_date (substr (B_Recorded_Date, 0, 10), ' MM/DD/YYYY'), ' MM/DD/YYYY') < to_char (to_date('12/31/2013','MM/DD/YYYY'), ' MM/DD/YYYY')
    )

    04/12/2013
    25/07/2000
    30/10/2003
    05/09/2006
    05/12/1994
    19/12/2013
    04/09/1992
    08/07/2007
    28/09/2005
    10/12/2004
    28/11/2011

    Thank you.

    Hello user7988

    Try this:

    SELECT *.

    OF Records_test

    WHERE

    TO_date (substr (B_Recorded_Date, 0, 10), ' MM/DD/YYYY') > = TO_DATE('07/01/2013','MM/DD/YYYY')

    AND TO_date (substr (B_Recorded_Date, 0, 10), ' MM/DD/YYYY')<>

    ;

    The best way if you set this column as DATE, then there is no need to convert your varchar value date.

    Kind regards
    David

  • Date ranges query

    Hi Experts,

    A very happy new year to all of you (a little in advance)!

    I have a table where I have the id of employee and the task assigned with the start dates and end dates. Overlap in the dates of the tasks is a data delivers however I know how to spot them and eliminate. There is therefore no date of tasks that overlap

    Employee_id

    Task_No

    Task_Start_date

    Task_End_Date

    Examples of data

    1 T1 1 January 2014 February 28, 2014

    1 T2 March 1, 2014 31 December 2014

    2 T1 23 January 2014 31 December 2014

    2 T2 1 January 2015 December 31, 2073 (means end of time)

    3 T3 1 January 2014 July 15, 2014

    3 T4 August 1, 2014 31 December 2014

    T5 4 1 January 2014 December 31, 2073

    I want to design a query where I provide the end date and it will list all the employees that are free for the same day from 1 January 2014. Thus, for example, if I give December 31, 2014, it will list the

    EmpId (first day where the employee is free)

    2 January 1, 2014

    3 July 16, 2014

    If I give the end = end date of time(31-Dec-2013), result-

    EmpId (first day where the employee is free)

    1 January 1, 2015

    2 January 1, 2014

    3 July 16, 2014

    If I give the end = date January 31, 2014, expected - result

    EmpId (first day where the employee is free)

    1 January 1, 2015

    I conceived after the request, but he intercepted not 2 employee ID. Also, it provides no flexibility to change end date-

    Select *.

    from (select employe_id,

    task_start_date,

    task_end_date,

    lag (task_end_date, 1, task_start_date) on prev_end_date (partition by employee_id arrested by task_start_date)

    of shop.employee_tasks

    where task_end_date > = trunc (sysdate))

    where task_start_date - prev_end_date > 1

    Thanks in advance!

    Kind regards

    This is an example of what I call the query 'free time': you have the dates when you are busy and you want the dates where you are free.

    You can find a nice solution for the problem of base here: ask Tom "SQL Query to find gaps in the date ranges" (search for solution of Anthony Boucher). Please note that this solution works even with the date ranges overlap.

    To apply the solution here, first create the test data (please do it yourself in the following questions).

    create table t(Employee_id, task_no, Task_Start_date, task_end_date)
    as select
    1, 'T1', to_date('01-jan-2014'), to_date('28-feb-2014') from dual union all select
    1, 'T2', to_date('01-Mar-2014'), to_date('31-Dec-2014') from dual union all select
    2, 'T1', to_date('23-jan-2014'), to_date('31-dec-2014') from dual union all select
    2, 'T2', to_date('01-jan-2015'), to_date('31-dec-2073') from dual union all select
    3, 'T3', to_date('01-jan-2014'), to_date('15-jul-2014') from dual union all select
    3, 'T4', to_date('01-aug-2014'), to_date('31-dec-2014') from dual union all select
    4, 'T5', to_date('01-Jan-2014'), to_date('31-Dec-2073') from dual;
    

    In the query, you must add records for yesterday and for the "end date" you want. This allows you to "free time" before and after the date ranges in your table.

    Now, you partition by order of Task_Start_date and employe_id. Using the analytical function of the max (task_end_date), you get the last date of end so far. Add 1 and you get the first time (maybe). To make sure that the date is free, it must be before the next start date.

    variable end_date varchar2(64)
    exec :end_date := '31-Dec-2073';
    --
    with boundaries as (
      select trunc(sysdate)-1 task_start_date, trunc(sysdate)-1 task_end_date from dual
      union all
      select to_date(:end_date)+1, to_date(:end_date)+1 from dual
    ), data as (
      select * from t
    where task_end_date >= trunc(sysdate)
      and task_start_date < :end_date
      union all
      select distinct a.employee_id, null, b.task_start_date, b.task_end_date
      from t a, boundaries b
    )
    select employee_id, min(free_start) free_start
    from (
      select employee_id,
      max(task_end_date) over (partition by employee_id order by task_start_date)+1 free_start,
      lead(task_start_date) over (partition by employee_id order by task_start_date)-1 free_end
      from data
    )
    where free_start <= free_end
    group by employee_id;
    
    EMPLOYEE_ID FREE_START
    1 JANUARY 1, 15
    2 1 JANUARY 14
    3 16 JULY 14
  • Receive every month between date Range

    Hi all

    I said you want to display the month and year for the date range. IE Start date: 01-11-12, end Date: 31/05/13

    SELECT COUNT(T1.CUST_NM) AS COUNT, TO_CHAR(T1.CREATE_DT,'MON-YY') AS MONTH, SUM(T3.DISBURSEMENT_LIMIT) AS TOTAL
      FROM CUSTOMER T1, 
     ACCOUNT T2, LOAN_ACCOUNT T3, CREDIT_APPL T4, PORTFOLIO T5 WHERE  T1.CUST_ID = T2.CUST_ID  AND T2.ACCT_ID = T3.ACCT_ID  AND T3.APPL_ID = T4.APPL_ID  AND 
     T4.PORTFOLIO_ID = T5.PORTFOLIO_ID
    and t1.CREATE_DT between to_date('01-01-10','DD-MM-YY') and  to_date('30-12-10','DD-MM-YY') 
     GROUP BY TO_CHAR(T1.CREATE_DT,'MON-YY')
    
    
    
    


    Exit SQL:

    CountyMonth-yearTotal
    8JAN-1015300
    6FEB-104245000
    11AUG-10144500
    6DEC-1015500

    Now SQL returns matching records to date. But the requirement is to display the name of the month, the number and total 0 if there is no data found.

    Power required:

    County Month-year Total
    8Jan15300
    1Feb-10118750
    0March-100
    0Apr-100
    0May - 100
    0Jun - 100
    0Jul-100
    11Aug-10144500
    0Seven.-100
    0Oct-100
    0Nov - 100
    6Dec - 1015500

    Please suggest me SQL to archive the above of the requirement.

    Thanks and greetings

    Saami

    Try this

    with t

    as

    (

    Select count (t1.cust_nm) as County

    to_char(t1.create_dt,'mon-yy') per month

    , sum (t3.disbursement_limit) total

    the t1 client

    in t2

    loan_account t3

    credit_appl t4

    the t5 portfolio

    where t1.cust_id = t2.cust_id

    and t2.acct_id = t3.acct_id

    and t3.appl_id = t4.appl_id

    and t4.portfolio_id = t5.portfolio_id

    and t1.create_dt between to_date ('01-01-10', ' dd-mm-yy')

    and to_date ('30-12-10', ' dd-mm-yy')

    Group

    by to_char(t1.create_dt,'mon-yy')

    )

    t1

    as

    (

    Select to_char (add_months (to_date('01-01-10','dd-mm-yy'), level-1), 'Mon - yy') month_list

    of the double

    connect

    by add_months (to_date('01-01-10','dd-mm-yy'), level-1)<= >

    )

    Select nvl (t.count, 0) as County

    t1.month_list per month

    , nvl (t.total, 0), as total

    from t1

    left

    Join t

    on t1. month_list = t.month

  • continuous data range algorithm

    I have in my database table 2 important date: (non-null) StartDate and EndDate (Null allowed).
    I want to assure that all records in the table always create perfect contiues to the beaches of dates without holes inside.
    WOR example there may be no records [1 - May... 1 may, 3-May-...] because there is a hole [2 - May... 2 may]. Holes are not permitted.
    And overlapping is not allowed, for example [1 - May... 1-may may-1-2 may, 3-May-...] is not allowed because the overlap takes place 1-may day. Overlap and the holes are not permitted. But it is possible that this table has no records at all. But all DML operations with existing records must ensure that overlapping and the holes occur.

    How to do this check? How to ensure that the data ranges would remain continuous without holes or overlapping?


    --
    Oracle 11g.

    You can use analytical functions to check the values of the next or previous lines to make comparisons, such as...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select 1 as id, 1 as val1, 4 as val2 from dual union all
      2             select 1, 5, 6 from dual union all
      3             select 1, 7, null from dual union all
      4             select 2, 1, 3 from dual union all
      5             select 2, 4, 7 from dual union all
      6             select 2, 9, 12 from dual union all
      7             select 2, 13, null from dual union all
      8             select 3, 1, 3 from dual union all
      9             select 3, 4, null from dual
     10            )
     11  --
     12  select id
     13        ,val1 as "start"
     14        ,val2 as "end"
     15        ,case when nvl(lag(val2) over (partition by id order by val1),0) != val1-1 then 'hole or overlap' else null end as chk
     16  from t
     17* order by 1, 2
    SQL> /
    
            ID      start        end CHK
    ---------- ---------- ---------- ---------------
             1          1          4
             1          5          6
             1          7
             2          1          3
             2          4          7
             2          9         12 hole or overlap
             2         13
             3          1          3
             3          4
    
    9 rows selected.
    
    SQL>
    

    Or the method tabibitosan can be used if the data should be...

    {: identifier of the thread = 1005478}

  • How to search between dates (date ranges)

    Is this possible in APEX to search between dates (date ranges) records in a report page? Like "DATE between P5-DATE AND SYSDATE? Thanks in advance.

    This might work:

    SELECT secuencia_pk, nombre_accidentado, num_caso_legal, numero_reclamante,
           num_seguimiento, status, descripcion
      FROM djur_registro
     WHERE INSTR (nombre_reclamante, NVL (:p2_nombre, nombre_reclamante)) > 0
       AND INSTR (nombre_accidentado, NVL (:p2_nombre_acc, nombre_accidentado)) >
                                                                                 0
       AND INSTR (num_caso_legal, NVL (:p2_num_legal, num_caso_legal)) > 0
       AND INSTR (numero_reclamante, NVL (:p2_num_reclamante, numero_reclamante)) >
                                                                                 0
       AND INSTR (num_seguimiento, NVL (:p2_num_segui, num_seguimiento)) > 0
       AND INSTR (descripcion, NVL (:p2_descripcion, descripcion)) > 0
       AND fecha_ocurrencia BETWEEN NVL (:p2_fecha_desde, fecha_ocurrencia)
                                AND NVL (:p2_fecha_hasta, SYSDATE)
    

    Denes Kubicek
    ------------------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Opal-consulting.de/training
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    ------------------------------------------------------------------------------

  • date range crosses / keys of other dates

    I have the table with columns 'HoldDate' and 'Release Date '.
    I want to ask all the records in the table, with my parameters pDateStart and pDateEnd in this way, which
    the date range [pDateStart.. pDateEnd] keys date range "HoldDate" and "Release Date".

    For example:

    Entry:
    pDateStart = the 20.03.2009
    pDateEnd = 23.03.2009

    1 Record1:
    "HoldDate" | "Release date".
    18.03.2009 | 19.03.2009

    This record NOT be returned by query, because the date range [20.03.2009..23.03.2009] do NOT touch / crosses the date range [18.03.2009..19.03.2009].

    2 Record2:
    "HoldDate" | "Release date".
    18.03.2009 | 21.03.2009

    This record will be returned by the query, because the range [18.03.2009..21.03.2009] dates date range [20.03.2009..23.03.2009] touch / intersect.

    What is the best way to write this condition to the query?

    I think it would be slow in the perfomance:

    WHERE the /pDateStart between HoldDate release date
    GOLD pDateEnd between HoldDate OF release date)

    Any thoughts?

    CharlesRoos wrote:
    I have the table with columns 'HoldDate' and 'Release Date '.
    I want to ask all the records in the table, with my parameters pDateStart and pDateEnd in this way, which
    the date range [pDateStart.. pDateEnd] keys date range "HoldDate" and "Release Date".

    What you need is...

    Where pDateEnd >= HoldDate AND pDateStart <= ReleaseDate
    
  • Conditional formatting depends on the date ranges

    Basically, I want to be able to enter a date in column A and a sum of money in the B column, depending on where the date in column A grave in a date range, I want the money in column B to copy to a corresponding column. Is this possible? The only questions I found on here deal in a conditional formatting with dates have to do with derivative.

    Thank you

    Julio

    I hope this help to clarify for you...

    It is not bringing conditional formatting.  Formatting conditional would change the format of a cell (or cells)... as the font, color, size, color cell background, or other formatting character is tics of a cell based on the contents of the cell

    You ask about including of the value of a cel another beach under certain conditions

    Here is an example:

    The first three rows are header lines.

    You must enter a valid date for the towing job.  Using the format "mm/dd/yyyy".

    C4 = IF (AND (DATEVALUE (A4) ≥DATEVALUE($B$1), DATEVALUE (A4) ≤DATEVALUE($B$2)), B4, "")

    It's shorthand dethrone select cell C4, and type (or copy and paste it here) the formula:

    = IF (AND (DATEVALUE (A4) ≥DATEVALUE($B$1), DATEVALUE (A4) ≤DATEVALUE($B$2)), B4, "")

    Select the cell C4, copy

    Select cells C4 at the end of the C column, paste

  • Tecra M5 does not record the date and time - battery RTC or CMOS checksum is inconsistent

    My Tecra M5 PTM50E reverend new does not record the date and time. I loaded RTC battery for 8 hours when electricity is on in the said user's manual. I don't know where is the problem. The BIOS settings are respect after power is on.

    When I change any value in the BIOS, the changes are saved properly but date & time system restored to their value 01/01/2000, 00:00 every time when I get out of turning off more of 2-3 min. Message "RTC battery is low or CMOS checksum is inconsistent.

    Press [F1] to set Date/time"does not appear when I power on the computer. Any suggestions?

    Hi guys

    Usually this problem appears only if the CMOS (real time clock) battery is empty or corrupted.
    The real time clock battery powers the internal clock in real time and calendar. It also maintains the system configuration. If the RTC battery is completely discharged, the system loses these data and the real-time clock. In this case, the message RTC battery is low or CMOS checksum is inconsistent appears.

    So I see only two possibilities:
    Either you will charge the battery for real-time clock, or you ask the technician for replacement.

    Generally, the battery must be completely charged after 8-9 hoers but try to connect the laptop to the power adapter for a long time.
    If it will not help solve the problem if you contact the ASP for the RTC battery replacement.

  • Smart album by date range does not select all the pictures, it should.

    I created a Smart Album with a range of the year.

    Some pictures appear in the Smart Album, but others do not, even though their information shows that their date corresponds to the range.

    I tried a repair of the photo library database, but that did not help.

    Try breaking the rule of date range: a buggy behavior reported in some language settings.

    This version shows more photos?

Maybe you are looking for