The date ranges whose value is on two different reporting periods

I have a SQL puzzle. How Can I with a single SQL statement GB of data like this to a reduced set of data knowing that a simple use of min/max does not correctly report 9494 x TVALUE is actually on two distinct periods separated by the 26202 x TVALUE. I messed around by using the analytical functions of the Oracle of lead and lag to see if if she me net anything or to reveal at least one model that I could take advantage of. It is probably with myself, but I'm not.

Any ideas?

EMPNO TVALUE TSTART TEND
"1234", "x 9494" 11/5/2007 12/5/2009 ".
"1234", "26202 x" 12/6/2009-4/30/2010 "»
"1234", "x 9494" 5/1/2010 8/18/2011 "»

OF THIS

EMPNO TVALUE TLAG TLEAD TSTART TEND
"1234" "0" '0""0' 10/16/2000-5/30/2002
"1234", "x 493" "0" "x 493" 5/31/2002-9/20/2003 ' "»
"1234" "x 493" "x 493" 'x 493' 9/21/2003-11/1/2003 ' "»
"1234", "x 493" "x 493" '0' 11/2/2003-4/17/2005 ' "»
"1234", "x 5821" "0" "x 5821" 4/18/2005-9/2/2006 "". "
"1234' ' x 5821" "x 5821" "x 5821" 9/3/2006-2/9/2007 "' '". "
"1234' ' x 5821" "x 5821" "x 5821" 2/10/2007-7/7/2007 "' '". "
"1234", "x 5821" "x 5821" '0' 7/8/2007 11/4/2007 ' "»
"1234", "x 9494" "0" "x 9494" 11/5/2007-5/9/2008 ' "."
"1234' ' x 9494" "x 9494" 'x 9494' 5/10/2008-12/20/2008 ' "."
"1234' ' x 9494" "x 9494" "x 9494" 21/12/2008-12/31/2008 "' '". "
"1234" "x 9494" "x 9494" "x 9494" 1/1/2009, 5/12/2009 "" "" "
"1234", "x 26202" '0""0' 12/6/2009-4/30/2010 "»
"1234", "x 9494" "x 9494" '0' 5/1/2010 8/18/2011 ""»
"1234", "x 3718" "0" "0" "8/19/2011-10/22/2011.
"1234", "x 76364" '0""0' 10/23/2011-12/31/4712 "»

FOR THIS

EMPNO TVALUE TSTART TEND
'1234' '0' 10/16/2000-5/30/2002
"1234", "x 493" 5/31/2002-4/17/2005 ".
"1234", "x 5821" 4/18/2005-11/4/2007 "»
"1234", "x 9494" 11/5/2007 12/5/2009 ".
"1234", "26202 x" 12/6/2009-4/30/2010 "»
"1234", "x 9494" 5/1/2010 8/18/2011 "»
"1234", «x 3718 "8/19/2011-10/22/2011"»
"1234", "x 76364" 10/23/2011-12/31/4712 "»

Ok. I think I understand your question now. I need to use the 'beginning of a group method:

with sample_table as (
                      select '1234' empno,'0' tvalue,'0' tlag,'0' tlead,to_date('10/16/2000','mm/dd/yyyy') tstart,to_date('5/30/2002','mm/dd/yyyy') tend from dual union all
                      select '1234','x493','0','x493',to_date('5/31/2002','mm/dd/yyyy'),to_date('9/20/2003','mm/dd/yyyy') from dual union all
                      select '1234','x493','x493','x493',to_date('9/21/2003','mm/dd/yyyy'),to_date('11/1/2003','mm/dd/yyyy') from dual union all
                      select '1234','x493','x493','0',to_date('11/2/2003','mm/dd/yyyy'),to_date('4/17/2005','mm/dd/yyyy') from dual union all
                      select '1234','x5821','0','x5821',to_date('4/18/2005','mm/dd/yyyy'),to_date('9/2/2006','mm/dd/yyyy') from dual union all
                      select '1234','x5821','x5821','x5821',to_date('9/3/2006','mm/dd/yyyy'),to_date('2/9/2007','mm/dd/yyyy') from dual union all
                      select '1234','x5821','x5821','x5821',to_date('2/10/2007','mm/dd/yyyy'),to_date('7/7/2007','mm/dd/yyyy') from dual union all
                      select '1234','x5821','x5821','0',to_date('7/8/2007','mm/dd/yyyy'),to_date('11/4/2007','mm/dd/yyyy') from dual union all
                      select '1234','x9494','0','x9494',to_date('11/5/2007','mm/dd/yyyy'),to_date('5/9/2008','mm/dd/yyyy') from dual union all
                      select '1234','x9494','x9494','x9494',to_date('5/10/2008','mm/dd/yyyy'),to_date('12/20/2008','mm/dd/yyyy') from dual union all
                      select '1234','x9494','x9494','x9494',to_date('12/21/2008','mm/dd/yyyy'),to_date('12/31/2008','mm/dd/yyyy') from dual union all
                      select '1234','x9494','x9494','x9494',to_date('1/1/2009','mm/dd/yyyy'),to_date('12/5/2009','mm/dd/yyyy') from dual union all
                      select '1234','x26202','0','0',to_date('12/6/2009','mm/dd/yyyy'),to_date('4/30/2010','mm/dd/yyyy') from dual union all
                      select '1234','x9494','x9494','0',to_date('5/1/2010','mm/dd/yyyy'),to_date('8/18/2011','mm/dd/yyyy') from dual union all
                      select '1234','x3718','0','0',to_date('8/19/2011','mm/dd/yyyy'),to_date('10/22/2011','mm/dd/yyyy') from dual union all
                      select '1234','x76364','0','0',to_date('10/23/2011','mm/dd/yyyy'),to_date('12/31/4712','mm/dd/yyyy') from dual
                     ),
               t1 as (
                      select  empno,
                              tvalue,
                              tstart,
                              tend,
                              case lag(tvalue) over(partition by empno order by tstart,tend)
                                when tvalue then 0
                                else 1
                              end start_of_group
                        from  sample_table
                     ),
               t2 as (
                      select  empno,
                              tvalue,
                              tstart,
                              tend,
                              sum(start_of_group) over(partition by empno order by tstart,tend) grp
                        from  t1
                     )
select  empno,
        tvalue,
        min(tstart) tstart,
        max(tend) tend
  from  t2
  group by grp,
           empno,
           tvalue
  order by tstart,
           tend
/

EMPN TVALUE TSTART     TEND
---- ------ ---------- ----------
1234 0      10/16/2000 05/30/2002
1234 x493   05/31/2002 04/17/2005
1234 x5821  04/18/2005 11/04/2007
1234 x9494  11/05/2007 12/05/2009
1234 x26202 12/06/2009 04/30/2010
1234 x9494  05/01/2010 08/18/2011
1234 x3718  08/19/2011 10/22/2011
1234 x76364 10/23/2011 12/31/4712

8 rows selected.

SQL> 

SY.

Tags: Database

Similar Questions

  • SUM (case use this structure to get average values on the date range

    I use:

    Oracle SQL Developer (3.0.04) build hand - 04.34 Oracle Database 11 g Enterprise Edition 11.2.0.1.0 - 64 bit Production

    How do we use the function sum with a structure of matter inside.

    so I gave that looks like have an ID, date and value. I'm looking to get the day 7 medium for the date range of 04/01/2013 to 20/04/2013
    with t as (
    select 1 ID_Key,to_date('4/1/2013','mm-dd-yyyy') date_val, 10 Value_num from dual union all
    select 1 ID_key,to_date('4/2/2013','mm-dd-yyyy'), 15 from dual union all
    select 1 ID_key,to_date('4/3/2013','mm-dd-yyyy'), 20 from dual union all
    select 1 ID_key,to_date('4/5/2013','mm-dd-yyyy'), 0 from dual union all
    select 1 ID_key,to_date('4/8/2013','mm-dd-yyyy'), 12 from dual union all
    select 1 ID_key,to_date('4/9/2013','mm-dd-yyyy'), 8 from dual union all
    select 1 ID_key,to_date('4/10/2013','mm-dd-yyyy'), 6 from dual union all
    select 1 ID_key,to_date('4/12/2013','mm-dd-yyyy'), 10 from dual union all
    select 1 ID_key,to_date('4/13/2013','mm-dd-yyyy'), 0 from dual union all
    select 1 ID_key,to_date('4/14/2013','mm-dd-yyyy'), 0 from dual union all
    select 1 ID_key,to_date('4/15/2013','mm-dd-yyyy'), 10 from dual union all
    select 1 ID_key,to_date('4/16/2013','mm-dd-yyyy'), 5 from dual union all
    select 1 ID_key,to_date('4/17/2013','mm-dd-yyyy'), 2 from dual union all
    select 1 ID_key,to_date('4/20/2013','mm-dd-yyyy'), 3 from dual union all
    select 2 ID_key,to_date('4/3/2013','mm-dd-yyyy'), 12 from dual union all
    select 2 ID_key,to_date('4/5/2013','mm-dd-yyyy'), 15 from dual union all
    select 2 ID_key,to_date('4/6/2013','mm-dd-yyyy'), 5 from dual union all
    select 2 ID_key,to_date('4/7/2013','mm-dd-yyyy'), 7 from dual union all
    select 2 ID_key,to_date('4/9/2013','mm-dd-yyyy'), 10 from dual union all
    select 2 ID_key,to_date('4/11/2013','mm-dd-yyyy'), 5 from dual union all
    select 2 ID_key,to_date('4/12/2013','mm-dd-yyyy'), 0 from dual union all
    select 2 ID_key,to_date('4/13/2013','mm-dd-yyyy'), 0 from dual union all
    select 2 ID_key,to_date('4/15/2013','mm-dd-yyyy'), 6 from dual union all
    select 2 ID_key,to_date('4/16/2013','mm-dd-yyyy'), 8 from dual union all
    select 2 ID_key,to_date('4/17/2013','mm-dd-yyyy'), 0 from dual union all
    select 2 ID_key,to_date('4/18/2013','mm-dd-yyyy'), 10 from dual union all
    select 2 ID_key,to_date('4/19/2013','mm-dd-yyyy'), 5 from dual
    )
    * Please let me know if the table does not load.

    I would get the average of 7 days, as long as there is date for the rank of enough previous dates, is it not, then it returns a null value.

    the results should look like this
    ID_Key      date_val     Value_num     7Day_Avg     7Day_Avg2
    1     4/1/2013     10          null          null
    1     4/2/2013     15          null          null
    1     4/3/2013     20          null          null
    1     4/5/2013     0          null          null
    1     4/8/2013     12          6.71          11.75
    1     4/9/2013     8          5.71          10.00
    1     4/10/2013     6          3.71          6.50
    1     4/12/2013     10          5.14          9.00
    1     4/13/2013     0          5.14          7.20
    1     4/14/2013     0          5.14          6.00
    1     4/15/2013     10          4.86          5.67
    1     4/16/2013     5          4.42          5.17
    1     4/17/2013     2          3.85          4.50
    1     4/20/2013     3          2.86          4.00
    2     4/3/2013     12          null          null
    2     4/5/2013     15          null          null
    2     4/6/2013     5          null          null
    2     4/7/2013     7          5.57          9.75
    2     4/9/2013     10          7.00          9.80
    2     4/11/2013     5          6.00          8.40
    2     4/12/2013     0          3.86          5.40
    2     4/13/2013     0          3.14          4.40
    2     4/15/2013     6          3.00          4.20
    2     4/16/2013     8          2.71          3.80
    2     4/17/2013     0          2.71          3.17
    2     4/18/2013     10          3.43          4.00
    2     4/19/2013     5          4.14          4.83
    As you can see, there are gaps in the dates, the value is then processed by zeros for the 7Day_Avg and then ignored for the 7Day_Avg2 (not counted in the number of days on average do to no valu_num line)
    I tried something like this at first, but becomes "missing keyword" error
    select
    t.*/,
    sum(
          case 
            when date_val between :day2 - 6 and :day2
            then value_num between date_val - 6 and date_val
            else null
            end
            )
            as 7Day_avg
    
    form t
    Should I have the structure outside the sum function?

    Any thoughts?

    Published by: 1004407 on June 7, 2013 11:06

    Hello

    If you want to calculate the average of the last 7 days, including the current day, then then RANGE should be 6 PRIOR, not 7.

    Try this:

    WITH got_min_date_val AS

    (

    SELECT id_key, date_val, value_num

    MIN (date_val) compared to (AS min_date_val)

    T

    WHERE the date_val BETWEEN TO_DATE (April 1, 2013 ', "dd-mm-yyyy")

    AND TO_DATE (April 20, 2013 ', "dd-mm-yyyy")

    )

    SELECT id_key, date_val, value_num

    CASE

    WHEN date_val > = min_date_val + 6

    THEN SUM (value_num) OVER (PARTITION BY id_key

    ORDER BY date_val

    PRIOR TO TIER 6

    )

    / 7

    END AS avg_7_day

    CASE

    WHEN date_val > = min_date_val + 6

    THEN AVG (value_num) OVER (PARTITION BY id_key

    ORDER BY date_val

    PRIOR TO TIER 6

    )

    END AS avg_7_day_2

    OF got_min_date_val

    ORDER BY id_key

    date_val

    ;

    Output:

    ID_KEY DATE_VAL VALUE_NUM AVG_7_DAY AVG_7_DAY_2

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

    1 1 APRIL 13 10

    1 2 APRIL 13 15

    1 APRIL 3, 13 20

    1 5 APRIL 13 0

    1 APRIL 8, 13 12 6.71 11.75

    1 APRIL 9, 13 8 5.71 10.00

    1 APRIL 10 13 6 3.71 6.50

    1 12 APRIL 13 10 5.14 9,00

    1 13 APRIL 13 0 5,14 7.20

    1 14 APRIL 13 0 5,14 6.00

    1 15 APRIL 13 10 4.86 5.67

    1 16 APRIL 13 5 4.43 5.17

    1 APRIL 17, 13 2 3.86 4.50

    1 APRIL 20, 13 3 2.86 4.00

    2 APRIL 3, 13 12

    2 5 APRIL 13 15

    2 6 APRIL 13 5

    2 7 APRIL 13 7 5.57 9.75

    2 9 APRIL 13 10 7,00 9.80

    2 11 APRIL 13 5 6.00 8.40

    2 12 APRIL 13 0 3.86 5.40

    2 13 APRIL 13 0 3.14 4.40

    2 15 APRIL 13 6 3.00 4.20

    2 16 APRIL 13 8 2.71 3.80

    2 17 APRIL 13 0 2.71 3.17

    2 18 APRIL 13 10 3.43 4.00

    2 APRIL 19, 13 5 4.14 4,83

    Post edited by: FrankKulash

    Sorry; I wanted to respond to OP, not Greg

  • With the help of case condition for the date of distinct values is does not

    Hello PL/SQL gurus and experts.

    I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64-bit Production version
    I followed two tables

    TT3-
    create table TT3(FeesCntlr,CommCntlr,LatePayCntlr,Name,Age) as select
    1,11,21,'Mike',25 from dual union all select
    2,12,22,'Clark',26 from dual union all select
    4,17,27,'Ussan',28 from dual union all select
    5,13,21,'Linda',29 from dual union all select
    6,14,24,'Obrek',35 from dual union all select
    7,15,25,'Batty',45 from dual union all select
    8,16,26,'Nicky',38 from dual;
    TT4
    drop table TT4;
    create table TT4(TRNID,BlockID,FeesCntlr,CommCntlr,LatePayCntlr,BookDate) as select
    221,625,1,11,21,20121101 from dual union all select
    223,625,2,12,22,20121101 from dual union all select
    224,625,1,11,21,20121101 from dual union all select
    225,627,4,17,27,20111001 from dual union all select
    226,628,5,13,21,20120701 from dual union all select
    227,628,6,14,24,20120701 from dual union all select
    334,628,7,15,25,20120701 from dual union all select
    339,629,8,16,26,20120701 from dual union all select
    393,629,1,11,21,20120701 from dual union all select
    432,629,2,12,22,20120701 from dual union all select
    347,629,1,11,21,20120701 from dual union all select
    556,629,4,17,27,20120701 from dual union all select
    558,629,5,13,21,20120701 from dual union all select
    974,629,6,14,24,20120701 from dual union all select
    976,629,7,15,25,20120701 from dual union all select
    980,629,8,16,26,20120701 from dual union all select
    1223,650,2,12,22,20110415 from dual union all select
    1224,650,1,11,21,20110415 from dual union all select
    1225,650,4,17,27,20110415 from dual union all select
    1226,650,5,13,21,20110415 from dual union all select
    1227,650,6,14,24,20110415 from dual union all select
    1334,650,7,15,25,20110415 from dual union all select
    1339,710,8,16,26,20120115 from dual union all select
    1393,710,1,11,21,20120115 from dual union all select
    1432,710,2,12,22,20120115 from dual union all select
    1347,710,1,11,21,20120115 from dual union all select
    1556,710,4,17,27,20120115 from dual union all select
    1558,711,5,13,21,20111231 from dual union all select
    1974,711,6,14,24,20111231 from dual union all select
    1976,711,7,15,25,20111231 from dual ;
    Now, if I use the following DML for the year 2012, then the result is as follows-
    SQL> select t3.Name,t3.age,count(t4.TRNID),count(distinct(BlockID)) from
      2  tt3 t3,tt4 t4
      3  WHERE     t3.feescntlr = t4.feescntlr
      4           AND t3.commcntlr = t4.commcntlr
      5           AND t3.latepaycntlr = t4.latepaycntlr
      6    AND t4.bookdate between 20120101 and 20121120
      7  GROUP BY t3.name, t3.age;
    
    NAME         AGE COUNT(T4.TRNID) COUNT(DISTINCT(BLOCKID))
    ----- ---------- --------------- ------------------------
    Mike          25              12                        3
    Mike          27              12                        3
    Batty         45               4                        2
    Clark         26               6                        3
    Linda         29               4                        2
    Nicky         38               6                        2
    Obrek         35               4                        2
    Ussan         28               4                        2
    
    8 rows selected.
    Now, if I use the following DML for 2011, then the result is as follows-
    SQL> select t3.Name,t3.age,count(t4.TRNID),count(distinct(BlockID)) from
      2  tt3 t3,tt4 t4
      3  WHERE     t3.feescntlr = t4.feescntlr
      4           AND t3.commcntlr = t4.commcntlr
      5           AND t3.latepaycntlr = t4.latepaycntlr
      6    AND t4.bookdate between 20110101 and 20111120
      7  GROUP BY t3.name, t3.age;
    
    NAME         AGE COUNT(T4.TRNID) COUNT(DISTINCT(BLOCKID))
    ----- ---------- --------------- ------------------------
    Mike          25               2                        1
    Mike          27               2                        1
    Batty         45               2                        1
    Clark         26               2                        1
    Linda         29               2                        1
    Obrek         35               2                        1
    Ussan         28               4                        2
    
    7 rows selected.
    But by using the condition if I use the following dml and results do not match-
    SQL> select Name,Age,sum(Trn),sum(CurYrOrdr) "2011 Order", sum(LastYrOrdr) "2012 Order"
      2  from
      3  (
      4  select t3.Name,t3.age,count(t4.TRNID) Trn,(case when t4.bookdate between 20110101 and 20111231 
    then count (distinct(BlockID)) else 0 end) CurYrOrdr,
      5  (case when t4.bookdate between 20120101 and 20121120 then count (distinct(BlockID)) else 0 end)
     LastYrOrdr
      6   from
      7  tt3 t3,tt4 t4
      8  WHERE     t3.feescntlr = t4.feescntlr
      9           AND t3.commcntlr = t4.commcntlr
     10           AND t3.latepaycntlr = t4.latepaycntlr
     11    AND t4.bookdate between 20110101 and 20121120
     12  GROUP BY t3.name, t3.age,t4.bookdate
     13  )
     14  group by Name,Age order by Name,Age;
    
    NAME         AGE   SUM(TRN) 2011 Order 2012 Order
    ----- ---------- ---------- ---------- ----------
    Batty         45          8          2          2
    Clark         26          8          1          3
    Linda         29          8          2          2
    Mike          25         14          1          3
    Mike          27         14          1          3
    Nicky         38          6          0          2
    Obrek         35          8          2          2
    Ussan         28          8          2          2
    
    8 rows selected.
    As the expected output, that I expect - is
    ----------------------------------
    
    Expected Output -
    NAME         AGE      "2012 TRNID"       "2011 TRNID"     "2012 ORDERID"     "2011 ORDERID"
    ----- ---------- --------------- ----------------------------- ---------- ------------
    Mike          25        12          2               3          1
    Mike          27        12              2          3          1
    Batty         45        4               2              2          1
    Clark         26        6               2              3          1
    Linda         29        4               2              2          1
    Nicky         38        6               2              2          1
    Obrek         35        4               2              2          1
    Ussan         28        4               4              2          2
    I sincerely thank each of you in advance for the input/comments that I fight with it for some time now.
    Kindly help.

    user555994 wrote:
    Hi JAC
    Thanks for the comments and certainly once I comment out the following line.
    - AND t4.bookdate between 20110101 and 20111120

    then the values are adapting, but at the same time why do we need to comment the date range condition as case is just a filter and not the condition.

    filter should be-

    AND t4.bookdate between 20110101 and 20121120 --"made it 12"
    
  • 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
    
  • On the date ranges in search of oracle forms

    I use service number, name, type person and date as search criteria in the custom form ranges.
    When I enter the employee number, press the search button, I get the exact info in the block of result.
    Result block contains
    name of the employee, personid, emp numbed, org, start_date.
    Similarly when I enter the employee number, dept, I get the correct values.
    My question is, when I enter the date range. IAM unable to filter the data.
    When I enter START_DATE between nvl(:BLOCKNAME.) Start_date, 1 January 1901 ') and nvl(:BLOCKNAME.) End_date, 31-DEC-4712') where block clause in the result. I had data for the range of dates also.

    If I give condition in where clause results take so long when I search with the name of the employee, number, dept, person type.

    If I have a query with the date, the persormance is good.

    Think you know everything, how it prevents START_DATE between nvl(:BLOCKNAME.) Start_date, 1 January 1901 ') and nvl(:BLOCKNAME.) End_date, 31-DEC-4712') when look us with the employee's name, number, dept, person type.

    So leave the WHERE clause of your empty block and put something like the following in your search button:

    IF    :BLOCK.START_DATE IS NOT NULL
       OR :BLOCK.END_DATE IS NOT NULL THEN
      SET_BLOCK_PROPERTY('YOURBLOCK', ONETIME_WHERE, 'START_DATE between nvl(:BLOCKNAME.START_DATE,TO_DATE(''01-JAN-1901'', ''DD-MON-YYYY'')) and nvl(:BLOCKNAME.END_DATE,TO_DATE(''31-DEC-4712'', ''DD-MON-YYYY''))');
    END IF;
    
  • get all the date of end of months between two dates

    Hi all, I'll try to find together the date of end of months between two dates.
    I have the following data in a table

    WITH AS's Data1
    (
    SELECT To_Date('4/30/2009','mm/dd/yyyy') dt, 'TEST' lname FROM dual UNION ALL
    SELECT To_Date('5/01/2009','mm/dd/yyyy') dt, "TEST2" lname FROM dual UNION all
    SELECT To_Date('5/02/2009','mm/dd/yyyy') dt, "TEST3" lname FROM dual UNION all
    SELECT To_Date('5/03/2009','mm/dd/yyyy') dt, "TEST4" lname FROM dual UNION all
    SELECT To_Date('5/04/2009','mm/dd/yyyy') dt, "TEST5" lname FROM dual UNION all
    SELECT To_Date('5/05/2009','mm/dd/yyyy') dt, "TEST6" lname FROM dual UNION ALL
    SELECT To_Date('5/31/2009','mm/dd/yyyy') dt, 'TEST7' lname FROM dual UNION all
    SELECT To_Date('6/01/2009','mm/dd/yyyy') dt, 'TEST' lname FROM dual

    )

    I would like to write an application that gives you all the end date for months between two dates
    for example, if you give the date 9/1/4 and 5/6/9, the output should be
    DT          LNAME
    -------------------
    4/30/2009   TEST
    IF I give you the dates 01/04/09 AND 01/06/09, THEN output should be
    DT          LNAME
    -------------------
    4/30/2009   TEST
    5/31/2009   TEST7
    as you can see, I want all the end dates of months between two dates by giving the output.

    If I give you 06/05/09 and 05/06/09, and then does so no output because there is no end of month between these two dates.
    Similarly, if I give you 30/04/09 and 30/04/09 then output should be 30/04/09 because it is an end of month date

    anyone can help to write a query. Thank you very much

    Jin
    Not sure if you need subquery, analytical functions for this.
    According to me, which should solve your purpose.

    WITH data1 AS
    (
    SELECT To_Date('4/30/2009','mm/dd/yyyy') dt, 'TEST' lname FROM dual UNION ALL
    SELECT To_Date('5/01/2009','mm/dd/yyyy') dt, 'TEST2' lname FROM dual UNION all
    SELECT To_Date('5/02/2009','mm/dd/yyyy') dt, 'TEST3' lname FROM dual UNION all
    SELECT To_Date('5/03/2009','mm/dd/yyyy') dt, 'TEST4' lname FROM dual UNION all
    SELECT To_Date('5/04/2009','mm/dd/yyyy') dt, 'TEST5' lname FROM dual UNION all
    SELECT To_Date('5/05/2009','mm/dd/yyyy') dt, 'TEST6' lname FROM dual UNION ALL
    SELECT To_Date('5/31/2009','mm/dd/yyyy') dt, 'TEST7' lname FROM dual UNION all
    SELECT To_Date('6/01/2009','mm/dd/yyyy') dt, 'TEST' lname FROM dual 
    
    )
    select distinct last_day(dt) dt,lname
      from data1
     where dt between &start_date and &end_date
       and last_day(dt) <= &end_date
    
    also, i have another request. how would i do this without using the data i provided. lets say,
     i tell you, give me alll the months end between two dates using dual in the from clause of a query.
    how would you do this in a query or pl/sql? thanks again
    

    Can be like that

    with data1 as(
    select &start_date+level-1 dt from dual
    connect by level <= &end_date-&start_date+1)
    select distinct last_day(dt)
      from data1
     where dt between &start_date and &end_date
       and last_day(dt) <= &end_date
     order by last_day(dt)
    

    See you soon!
    Bobin

    Published by: Buga added query for updated the need

  • Can I set up custody of data between databases already available on two different servers?

    Hi, people

    Can I set up custody of data between databases already available on two different servers? If Yes please can you share the links.

    Host operating system: business Red hat Linux 6.5, 64-bit

    The two DB: Oracle 11.2.0.1

    Thank you

    But my question is that I have already two databases running on two different servers that have different data as well.

    In this case we can able to configuration data guard on these two databases.

    The answer may well be yes or no depending on what exactly you mean. Let me explain... Suppose that my Setup matches your description. I have two database servers, we will call them HOST01 and HOST02. HOST01, I have a database named ORCL1 and HOST02 I have a totally different database named ORCL2. Two databases... two hosts.

    Can I do ORCL2 a physical database ensures for ORCL1? The answer is no, I can't. I can't use another existing database to be one physical standby of another. ORCL2 must be destroyed and ORCL1 copied to HOST02 so that I have a database of duplicate.

    Can I use ORCL2 logical waiting for ORCL1? Yes. However, it would be a rare configuration.

    Can I copy ORCL1 to HOST02 and create a physical standby of ORCL1 on HOST02? And then can copy ORCL2 to HOST01 and HOST01 to provide a physical standby for ORCL2? The answer to both is Yes. You can have the other provide a standby for the guests of the database have sufficient resources to support the primary one and the expectation of the other.

    HTH,

    Brian

  • Impossible to get Min, Max and median of the values in the date range values

    Hello

    I had a requirement as to show the data of each charge group of wise men as '< 100' ' 100-199 "" 200-299 "" 300-399 "400-499, 500-599 600-699 700-799 800-899 900-999 > = 1000 '"»

    With the query be able to get the count between the beach and the total below. But impossible to get the Min and Max values for this range. For example if the County < 100 is 3 then in these 3, the lowest value is need to display in the min. Idem for Max column also.

    In the light of the median value on these values.

    Thanks in advance.



    Requirement is as below:
    State < 100 100-199, 200-299 300-399 400-499, 500-599 600-699 700-799 800-899 900-999 > = 1000 Min Total median Max
    AK 1 2 0 4 1 4 4 35 35 4 1 $25 $85 850 $1,200
    AL 0 0 2 27 10 17 35 2 2 35 0 $103 100-$1 500 750


    * "QUERY ' * '"

    WITH t AS
    (SELECT 'AL' State, 12 DUAL FROM VALUE
    UNION ALL
    SELECT 'AL' State, 67 FROM DUAL VALUE
    UNION ALL
    SELECT 'AL' State, 23 FROM DUAL VALUE
    UNION ALL
    SELECT 'AL' State, 12 DUAL FROM VALUE
    UNION ALL
    SELECT 'AL' State, 12 DUAL FROM VALUE
    UNION ALL
    SELECT 'AL' State, 78 FROM DUAL VALUE
    UNION ALL
    SELECT 'AL' State, 34 FROM DUAL VALUE
    UNION ALL
    SELECT 'AL' State, 4 DUAL FROM VALUE
    UNION ALL
    SELECT 'AL' State, 12 DUAL FROM VALUE
    UNION ALL
    SELECT 'AL' State, 15 VALUE FROM DUAL
    UNION ALL
    SELECT "AZ" State, FROM DUAL VALUE 6
    UNION ALL
    SELECT "AZ" State, 123 FROM DUAL VALUE
    UNION ALL
    SELECT "AZ" State, 123 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 23 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 120 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 456 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 11 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 24 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 34 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 87 DUAL FROM VALUE
    UNION ALL
    SELECT 'MY' State, 23 FROM DUAL VALUE
    UNION ALL
    SELECT 'MY' State, 234 DUAL FROM VALUE
    UNION ALL
    SELECT 'MY' State, 789 FROM DUAL VALUE
    UNION ALL
    SELECT "HD" State, VALUE FROM DUAL 54321).
    -End of test data
    AS T1
    (SELECT State,
    NVL (COUNT (DECODE (VALUE, 0, 0)), 0) '< 100 ',.
    NVL (COUNT (DECODE (VALUE, 1, 1)), 0) '100-199.
    NVL (COUNT (DECODE (VALUE, 2, 2)), 0) '200-299.
    NVL (COUNT (DECODE (VALUE, 3, 3)), 0) '300-399.
    NVL (COUNT (DECODE (VALUE, 4, 4)), 0) '400-499.
    NVL (COUNT (DECODE (VALUE, 5, 5)), 0) '500-599,'
    NVL (COUNT (DECODE (VALUE, 6, 6)), 0) '600-699.
    NVL (COUNT (DECODE (VALUE, 7, 7)), 0) '700-799.
    NVL (COUNT (DECODE (VALUE, 8, 8)), 0) '800-899.
    NVL (COUNT (DECODE (VALUE, 9, 9)), 0) '900-999. "
    NVL (COUNT (DECODE (VALUE, 10, 10)), 0) ' > = 1000.
    (SELECT STATE,
    CASE
    WHAT VALUE < 100 THEN 0
    WHAT A VALUE BETWEEN 100 AND 199 THEN 1
    WHAT VALUE BETWEEN 200 AND 299, THEN 2
    WHAT VALUE BETWEEN 300 AND 399 THEN 3
    WHAT VALUE BETWEEN 400 AND 499 THEN 4
    WHAT VALUE BETWEEN 500 AND 599 5 THEN
    WHAT VALUE BETWEEN 600 AND 699 6 THEN
    WHAT VALUE BETWEEN 700 AND 799 THEN 7
    WHAT VALUE BETWEEN 800 AND 899 8 THEN
    WHAT VALUE FROM 900 TO 999 9 THEN
    WHAT VALUE > = 10 THEN 1000
    END
    VALUE
    T)
    GROUP BY State)
    SELECTION STATE,
    "< 100."
    "100-199.
    "200 299",
    "300-399.
    "400-499.
    '500-599,'
    "600-699.
    "700-799.
    "800-899.
    "900-999."
    "> = 1000."
    '< 100 '.
    + "100-199.
    + "200-299.
    + '300-399.
    + '400-499.
    + "500-599.
    + '600-699.
    + "700-799.
    + "800-899.
    + '900-999 ".
    + ' > = 1000.
    in total,.
    less ("< 100",)
    "100-199.
    "200 299",
    "300-399.
    "400-499.
    '500-599,'
    "600-699.
    "700-799.
    "800-899.
    "900-999."
    ("> = 1000 ') min_val,.
    largest ("< 100",)
    "100-199.
    "200 299",
    "300-399.
    "400-499.
    '500-599,'
    "600-699.
    "700-799.
    "800-899.
    "900-999."
    ("> = 1000 ') max_val
    FROM t1
    /

    Why not keep it simple?

    WITH t AS
    (SELECT 'AL' state, 12 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 67 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 23 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 12 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 12 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 78 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 34 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 4 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 12 VALUE FROM DUAL
    UNION ALL
    SELECT 'AL' state, 15 VALUE FROM DUAL
    UNION ALL
    SELECT 'AZ' state, 6 VALUE FROM DUAL
    UNION ALL
    SELECT 'AZ' state, 123 VALUE FROM DUAL
    UNION ALL
    SELECT 'AZ' state, 123 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 23 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 120 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 456 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 11 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 24 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 34 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 87 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 23 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 234 VALUE FROM DUAL
    UNION ALL
    SELECT 'MA' state, 789 VALUE FROM DUAL
    UNION ALL
    SELECT 'MH' state, 54321 VALUE FROM DUAL)
    SELECT state
         , NVL( COUNT( case when VALUE < 100 then 0 end ), 0 ) "<100"
         , NVL( COUNT( case when VALUE between 100 and 199 then 0 end ), 0 ) "100-199"
         , NVL( COUNT( case when VALUE between 200 and 299 then 0 end ), 0 ) "200-299"
         , NVL( COUNT( case when VALUE between 300 and 399 then 0 end ), 0 ) "300-399"
         , NVL( COUNT( case when VALUE between 400 and 499 then 0 end ), 0 ) "400-499"
         , NVL( COUNT( case when VALUE between 500 and 599 then 0 end ), 0 ) "500-599"
         , NVL( COUNT( case when VALUE between 600 and 699 then 0 end ), 0 ) "600-699"
         , NVL( COUNT( case when VALUE between 700 and 799 then 0 end ), 0 ) "700-799"
         , NVL( COUNT( case when VALUE between 800 and 899 then 0 end ), 0 ) "800-899"
         , NVL( COUNT( case when VALUE between 900 and 999 then 0 end ), 0 ) "900-999"
         , NVL( COUNT( case when VALUE >= 1000 then 0 end ), 0 ) ">=100"
         , count( value ) "total"
         , min( VALUE ) "min"
         , max( VALUE ) "max"
         , avg( VALUE ) "avg"
         , median( value ) "median"
    from t
    group by state
    
  • How to calculate the periods that overlap between two or more given the date range?

    Hi all

    If there are several durations then how we can calculate the period of time that overlap between these times.

    For example: for 3 time periods. 03/12/2015-16/08/2015, 05/01/2015 to 31/07/2015 and the 06/09/2015 to 30/11/2015, how the overlap period can be calculated?

    There are many potential unknowns in your question.  For example, you want to count any overlap at all?  If two dates overlap, what matters?  Overlap - each of them?

    In any case, here is a solution that counts how many periods are overlapping in any point in time...  She, of course, using temporal logic.  You can then use ValueAt(), WhenLast(), WhenNext(), etc. as appropriate.

    Assume that your model has a child entity called 'the period' with name 'all time periods' relationship and basic attributes 'start date of the period of time' and 'date of end of period of time'.

    In your example:

    an entity should have the time period start date = 03/12/2015 and the date of end of period of time = 16/08/2015

    another entity might have the time period start date = 01/05/2015 and the date of end of period of time = 31/07/2015

    another entity might have the time period start date = 06/09/2015 and the date of end of period of time = 30/11/2015

    To find the number of overlapping over time, we want to count or entities that have an active period, so the rule is perhaps the sum:

    the number of overlapping = the number of all the periods for which it is true that the time period is active

    How do we know a time is active?  This is the time logic comes in.  He is active on or after the start date or no later than the end date:

    the time period is active if

    TemporalOnOrAfter (the date of beginning of period of time) and

    TemporalOnOrBefore (date of end of period of time)

    That's all.  Now, you can perform a temporal visualization of the 'number of overlapping' and you'll see it rise and fall over time.  As a reference, he said that the number of overlapping = 3.0 from 06/09/2015 across 31/07/2015.

    I hope this helps.  You can use the same model to count periods of time functions, but you end up having to use the most logical date.  You of course can count the total number of entities and compare this number of overlap over time to see if they overlap, but I digress...

  • How to pass the date range as in URL filter go

    Hello

    I am trying to build a Url go that has two filters, date range & text. I built the url below, but he continues to throw an error. The url is not from the date max and the app starts following error:

    Error: Status: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 46048] Month DateTime value 0 0000-00-00 is off limits. (HY000)

    Go to Url: https:companyUrl? GB & Options = rfd & Path = / shared/CompanyID/link & P0 = 2 & P1 = eq & P2=CustomObject4.%22Indexed%20Pick%201%22 & P3 = Leasing & bet = P4 & P5 = ""-CustomObject4 Custom Attributes '. " ZDate_26 & P6 = 2 + Date % 20'2014-08-01'+ day % 20'2014-12-31'


    Please suggest.

    Thank you
    Kiran.

    It seems that you convert the data type of char to date in the URL, I don't think that this is possible.
    Your code is like
    & P6 = 2 + Date % 20'2014-08-01'+ day % 20'2014-12-31'

    It suppose to be & P6 = 2 + 2014-08-01 + 2014-12-31

    I suggest doing the formatting for this filed using column properties and try.

    Hope this help, pls mark if yes ;)

  • 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

  • To ignore the date ranges that overlap

    Hi guys,.

    I have the tables below

    Periods

    START_DATEEND_DATEID
    30-SEP-0513 OCTOBER 051
    12 OCTOBER 0514 NOVEMBER 052
    15 NOVEMBER 0515 DECEMBER 053

    T1

    DAT_COLIDAMOUNT
    11 OCTOBER 05110
    12 OCTOBER 05110
    16 NOVEMBER 05110

    I need to ignore the remaining date range if it overlaps when comparing dat_col from T1 between the dates of beginning and end of periods table. Always need to consider the first periods

    output something like this

    IDID_1START_DATEEND_DATEDAT_COL
    1130-SEP-0513 OCTOBER 0511 OCTOBER 05
    1130-SEP-0513 OCTOBER 0512 OCTOBER 05
    1315 NOVEMBER 0515 DECEMBER 0516 NOVEMBER 05

    I use query

    Select a.id, b.id, b.start_date, b.end_Date, a.DAT_COL from T1 a, (select id, start_date, end_date periods) b

    where a.dat_col between b.start_Date and b.end_Date

    Group of a.id, b.id, b.start_date, b.end_Date, a.dat_col

    order of b.start_date;

    IDID_1START_DATEEND_DATEDAT_COL
    1130-SEP-0513 OCTOBER 0511 OCTOBER 05
    1130-SEP-0513 OCTOBER 0512 OCTOBER 05
    1212 OCTOBER 0514 NOVEMBER 0512 OCTOBER 05
    1315 NOVEMBER 0515 DECEMBER 0516 NOVEMBER 05

    Test case:

    CREATE TABLE 'PERIODS '.

    ("START_DATE" DATE,

    "END_DATE" DATE,

    'ID '.

    ) ;

    Insert into periods (start_date, end_date, ID) values (to_date('30-SEP-05','DD-MON-RR'),to_date('13-OCT-05','DD-MON-RR'),1);

    Insert into periods (start_date, end_date, ID) values (to_date('12-OCT-05','DD-MON-RR'),to_date('14-NOV-05','DD-MON-RR'),2);

    Insert into periods (start_date, end_date, ID) values (to_date('15-NOV-05','DD-MON-RR'),to_date('15-DEC-05','DD-MON-RR'),3);

    Insert into T1 (DAT_COL, ID) values (to_date('11-OCT-05','DD-MON-RR'), 1);

    Insert into T1 (DAT_COL, ID) values (to_date('12-OCT-05','DD-MON-RR'), 1);

    Insert into T1 (DAT_COL, ID) values (to_date('16-NOV-05','DD-MON-RR'), 1);

    CREATE TABLE 'T1 '.

    (DATE OF THE 'DAT_COL',

    'ID '.

    );

    Hello

    If you really want to use something close to what you posted, then you can do it like this:

    WITH got_r_num AS

    (

    SELECT a.id

    b.id AS id_1

    b.start_date

    b.end_date

    a.dat_col

    , ROW_NUMBER () OVER (PARTITION BY a.id, a.dat_col)

    ORDER BY b.start_date, b.end_date

    ) AS r_num

    FROM one t1

    ,         (

    SELECT id, start_date, end_date

    Periods

    ) b

    WHERE a.dat_col BETWEEN b.start_date

    AND b.end_date

    GROUP BY a.id, b.end_date, a.dat_col, b.start_date and b.id

    )

    SELECT id, id_1, start_date, end_date, dat_col

    OF got_r_num

    WHERE r_num = 1

    ORDER BY start_date

    ;

    Note that the WITH clause, that's essentially what you posted in your first post (with the added r_num column) and the main request is essentially the same as in response #1.

    But why would you do something like that?  View online or GROUP BY allows all.  If you remove them, you get the #1 response solution.

  • Get the date range min/max for consecutive events.

    Hi all...

    I am fairly new to the programming of the DB and is working on some examples I picked up a few places. The database version is 10g R2.

    I would like to configure the data here and I can explain my requirement.

    create table table_1
    (product_id varchar2(25),
    region_id  number,
    event_id number
    event_date date,
    event_status number(1))
    /
    
    
    

    Now the data because it is->

    insert into table_1 values ('Prod-1',10, null, to_date('01-feb-2014','dd-mon-yyyy'),null)
    /
    insert into table_1 values('Prod-1',10, 1001, to_date('10-mar-2014','dd-mon-yyyy'), 1)
    /
    insert into table_1 values('Prod-1',10, 1001, to_date('20-mar-2014','dd-mon-yyyy'), 3)
    /
    insert into table_1 values('Prod-1',10,1002, to_date('01-apr-2014','dd-mon-yyyy'), 1)
    /
    insert into table_1 values('Prod-1',10, 1002, to_date('10-apr-2014','dd-mon-yyyy'), 3)
    /
    commit
    /
    
    
    
    

    If the table now contains the following data

    select * from table_1; 
    
    
    

    PRODUCT_ID REGION_ID EVENT ID EVENT_DAT EVENT_STATUS

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

    Prod-1 10 1 February 14

    Prod-1 10 1001 10 March 14 1

    Prod-1 10 1001 20 March 14 3

    Prod-1 10 1002 1 April 14 1

    Prod-1 10 1002 April 10, 14 3

    Now, the condition is as follows:

    Above is the dates start and end for the tests on a product in a given region. The event_status column indicates the dates of beginning and end. Event_status = 1, for the date of beginning and the event_status = 3 of the end date.

    A new event is now coming from March 21 and ending on March 31.

    The power required is a product identifier / region; If there are events that are ending and then count the days, for example, 1001 to end on March 20, but now the new event begins on 21 March... and the new event ends on 31 March and event 1002 begins 01 - Apr... and so on.

    The output required for this is as follows:

    PRODUCT_ID REGION_ID EVENT_MIN_DATE EVENT_MAX_DATE

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

    Prod-1 10 10 14 March 10 April 14

    The output should give a product identifier / region, when events are immediately after the other, out the min date of beginning and end of max for all these manifestations of "back to back".

    Now I wrote the code for this, but it goes into a purely 'loop' for application in PLSQL... But my head tells me that if the results are correct. the PLSQL implementation is not the most efficient and effective way.

    Can someone help me to form the query? I tried to use functions analytical min/max but it gives me the start and end dates back even if my events are not "back to back" or previous/succeed each other... so my query result is not quite correct.

    Am reading on the TYPE clause but would be grateful if someone could help me with this query... or any other form better to implement this event so PLSQL can be used. The database version is 10g R2.

    Thank you

    K

    PS - The number of such events back to back is limited to 4 and the events could be created in any order. But if someone could help me with the scenario above; am sure I could make a request addressed to any change in the order. :-)

    No this isn't a recursive with clause, perhaps the UNION ALL you got confused. She will work with 10g.

    Since there are 2 tables that you said, the block all_data brings together only the lines of the two tables. table_1 start_date and end_date are built from the event_status (where the max in group by).

  • When you change the date range, some data refresh some is not the case.

    In looking at some the report explore end-user (EU - FxM cartridge), I noticed that some data are updated based on the data and the time I selected. I noticed that the response time service level and measures processing time service level (metric in the green circle) doesn't refresh at all. I noticed the same behavior when you look at some different indicators in the report to explore end-user. Anyone encountered this?

    I think you are referring to this point of view, but I don't know how you got there from the browser of the end user:

    Looking at the Design tab in the right pane of Action and selecting the view "user end/FxM/Applications/Application Service level Layout" to inspect, it turns out that "jelly bean" service level indicators are configured to display:

    / responseTimeServiceLevel/value/latest/min

    / processingTimeServiceLevel/value/latest/min

    As the notes of Osama, the "last" value here will not change when the time interval of page is updated.

    Contrary to what he says, if this dashboard has been configured to display the "current" value, these indicators would show the last value not expired before the end of the time range of page.

    You can:

    -Open a session to demand that this configuration of the dashboard be changed in a future release, a matter of pension

    -change this system view (which will not survive an upgrade of the FxM cartridge)

    -(deep) to copy the view "User end/FxM/Applications/FxM information request" and change the copied view (which survive and upgrade). You must also change the type mapping "FxM Application result" in Applications/FxM/end user to point to your point of view, updated the.

    Kind regards

    Brian Wheeldon

  • The smart Albums based on the date range cause app Crash Photos

    While I'm setting up a new Smart Album based on day of photos between 12/01/2015 and 31/12/2015 the Photos app closes with a crash. Cannot set the second date (the end date for this album). However, I can easily create a new Smart Album for next month (01/01/2016 and 01/31/2016). I create smart Albums, because the new Photos app does not like the old iPhoto does with my Photos from the photo gallery.

    How can I solve this? I don't have an album of December...? !

    You are in an area where the date format is different from the United States?  Earlier this year, we have seen small business issues have reported that rules for smart albums date range do not work with the primary language set to French or German.

    Try to change the primary system language to English with an English date format. Photos could be trying to read the 12/31/2015 as the 12th day of the month 31.

    Or use a different date based on 'before' rule and after.

Maybe you are looking for

  • Unexpected restarts in Satellite P100 WXP MCE

    Satellite P100-342 - PSPA3E 10 months. From the beginning, the pc restarts unexpectedly during a working session every 5 minutes on. A full recovery does not solve the problem. The pc was sent 3 times to the Toshiba technical service: motherboard, me

  • Equium A210 - Question on two 2 hard drives using Vista

    I'm looking for some portable refurbished Toshiba and see that some of them (including the title template) have 2 hard drive bays. An individual has a specified 80 GB drive and I am puzzled as to how, if the 80 GB is divided, it can run Vista. I inte

  • notice of nonpreset mode at startup

    How can I get rid of this notice. He is just starting to show the full process

  • Size of partition using Bloom filters

    HelloOracle EE 11.2.0.4, ExadataBelow is a very simple test query:explain plan forSelect * from t1where (c1, c2) in(select c1, c2 from gtt_t2);We have two very similar patterns, these two objects. We copy the stats on patterns, so that all objects ha

  • InDesign crashes at the start of the Application, why? How can I fix?

    Since I downloaded and installed Mac OS X El Captain (and maybe its coincidence) InDesign crashes instantly after opening the application. I uninstalled the application using the creative application cloud and then installed again, I rebooted my comp