1 each range interval data retrieval

Hi guys

I have this game of number, for example. 12 13 201 243 303 584 674 698 731 745 768 800. So what I want to do is to extract the highest number in each interval of 100. For example, in the range of 0 to 100, 13 will only be extracted from.

Finally, all the data in the result loop must be an array of 13 243 303 584 698 768 800.

I tried to use a nested loop and a false true case with table generation, but I couldn't get the setting I want. Please help me on this thank you.

In addition, each number on the top is accompanied by another number, meanwhile extract the data I have, I'd be the number that goes with it on the next column.

See you soon

PX

This assumes that your table is sorted.

If you use the rest quotient function between the current value and the following in your table and compare the quotients, you will know if the next value is a new hundred, making it the largest present value number in the current one hundred.

Tags: NI Software

Similar Questions

  • Filter for table data, the range of data obtained and defined 2D

    I produce data of an ultrasonic sensor at 1 K Hz, and there is a lot of data (data points range of 0 to 10). However, in some cases when I know that the data should be about 7 (for example) I get outliers (about 9 and 10). Is it possible to define a filter for data in the defined range.

    I averaged the data to get an average value, and outliers are distorting. In the worst case, my outliers are 30 to 40% of the data generated. I created a filter to sort the data and, taken from the lowest value. I stop the loop when data reaches a value greater then 9. But this seems to take a long time (because the loop checks for each data point and there are 1000s of them).

    Is there a better way to filter data and define a predefined table range to collect?

    I enclose my filter.vi... and a set of samples of my previous data. The ranges of data of 10-8 and would like to have the range 7.5 to 8.5 to consider. The sensor records tension here and the problem can be solved by installing a different type of sensor, but if a filter in LabView can due it, the sensor that we use now is absolute.

    I am in kind of emergency, my design in unfinished because of this problem, if someone can find some time to share some suggestions, I will be grateful.

    Thanks in advance.

    See attachment.  I have incorporated the data you've posted in the vi.  It doesn't seem like any data were less than 8.7 or so, so I modified the scope so it would be a few points on average.  Some games were completely out of reach while the average came back like NaN (not a number) due to a division by zero.

  • How to define the range of data to a strict typdef through the control reference

    Hello world

    I'm trying to define the range of data to a strict typdef through the reference of the order, when I do, I get an 'error of property node.

    Is it possible to set the range of the strict typdef.

    Thank you

    Vignesh

    Vignesh1987 wrote:

    I'm trying to define the range of data to a strict typdef through the reference of the order, when I do, I get an 'error of property node.

    Is it possible to set the range of the strict typdef.

    Try to set the original control (type-def) and not its instances... to open the reference of the original type-def command, use 'Open VI reference'.

    Published:

    These properties are not available with STRICT TYPE DEF.

    a. data entry limits: increment property

    b. data entry property of limits: Maximum

    c. property limits: Minimum for the data entry

  • How to filter for a range of dates calendar events in OS10

    In earlier versions of BlackBerry, I used blackberry.find.FilterExpression to filter the events calendar for a specific range of dates.

    However for BlackBerry OS10 I scoured the web to find a way to do it. I found:http://developer.blackberry.com/html5/apis/blackberry.pim.calendar.calendarfindoptions.html

    I also googled a lot of other sites, but I am unable to understand how to use CalendarFindOptions to refine the calendar of events of a specific timetable. For example, the current week or the next 7 days.

    I found this code example...
    Function listEvents (limit) {}
    Calendar var = blackberry.pim.calendar;
      var CalendarFindOptions = calendar. CalendarFindOptions;
      var findOptions = {}
    'Sort': [{}
    "fieldName": CalendarFindOptions.SORT_FIELD_SUMMARY.
    'desc': false
    }],
    'detail': CalendarFindOptions.DETAIL_AGENDA,
    'limit': limit
    };

    But unable to find examples how adequately limited by date?
    I'm guessing that something like this:
    'Start': new Date (' January 1, 2013, 13:00 "): CalendarFindOptions.SORT_FIELD_START.
    'end': new Date (' January 1, 2013, 16:00 "): CalendarFindOptions.SORT_FIELD_STOP.

    But it is an assumption and does not work I can find no example of how do

    Any help would be appreciated

    See the example for pimcalendar on Github:

    https://github.com/BlackBerry/BB10-WebWorks-samples/tree/master/pimcalendar

    You can find the JS to set filters of beginning and end starts here:

    https://github.com/BlackBerry/BB10-WebWorks-samples/BLOB/master/pimcalendar/index.html#L107

  • How can I "RECORD each piece of data (and I mean everything!)" contained in the hard disk of the laptop? »

    How can I "RECORD each piece of data (and I mean everything!)" contained in the hard disk of the laptop? »

    I know PC never fade completely everything, so if there is a way to get personally, I'd really like the head upward on the how to do?  I would be better for me to download all this information on a PHDD, rather than handing the portable real in question so that its content of forensics experts, because current 'Communications Network serious security' we have been subjected to.

    Here you go:

    1. Use an imaging program to create a clone of your hard drive.
    2. Delete the original from your PC hard drive and keep it somewhere safe.
    3. Put the clone in the PC.
    It is the only way to really keep all while still able to use the PC.
  • Report with 2 settings of filtering by day and 3 measures for a range of dates

    Hello

    I need to establish a relationship with the following criteria:

    (a) I have 5 settings

    (b) tell of 2 measures of data should be based on a date 01/01/2015

    (c) rest of 3 data measures should be based on a range of dates say 01/01/2015-31/01/2015

    No idea how to achieve this?  If so please help me.

    Thanks in advance

    LonaD

    You cannot filter the reports by using the filter function in the formula in the column?

  • At least a record exists in details that cover the range of dates

    Oracle version:

    Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production

    Hi gurus

    I'm stuck with a scenario and your employees need help to solve this problem.

    I have the following table:

    Insertion and table creation

    drop table ident;

    create table ident

    (

    agreement_id number (5),

    ident_pk number (5),

    Date of Cov_effective_date,

    Date of Cov_termination_date

    );

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

    Insert ident

    (

    Select 100,1,to_date('2013-01-01','YYYY-MM-DD'), double to_date('2013-01-31','YYYY-MM-DD')

    Union of all the

    Select 200,2,to_date('2013-01-01','YYYY-MM-DD'), double to_date('2013-12-31','YYYY-MM-DD')

    Union of all the

    Select 300,3, to_date ('2013-03-01 ',' YYYY-MM-DD '), double null

    );

    Query on table

    Select * ident;

    Agreement_id ident_pk Cov_effective_date Cov_termination_date

    100113/01/0113/01/31
    200213/01/0113/12/31
    300313/03/01

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

    Drop table ident_dtl;

    create the table ident_dtl

    (

    ident_pk number (5),

    ident_dtl_pk number (5),

    date of effective_date,

    date of termination_date

    );

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

    insert into ident_dtl

    (

    Select 1-ident_pk, 10 ident_dtl_pk, to_date('2013-01-01','YYYY-MM-DD') effective_date, to_date('2013-01-31','YYYY-MM-DD') termination_date of double - to agreement_id = 100

    Union of all the

    Select 1,11,to_date('2013-01-01','YYYY-MM-DD'), to_date('2013-01-30','YYYY-MM-DD') of double - to agreement_id = 100

    Union of all the

    Select 2,12,to_date('2013-01-01','YYYY-MM-DD'), to_date('2013-01-30','YYYY-MM-DD') of double - for agreement_id = 200

    Union of all the

    Select 2.13, to_date('2013-01-01','YYYY-MM-DD'), double to_date('2013-01-15','YYYY-MM-DD') - for agreement_id is 200

    Union of all the

    Select 3.14, to_date('2013-01-01','YYYY-MM-DD'), double to_date('2013-01-15','YYYY-MM-DD') - for agreement_id = 300

    Union of all the

    Select 3.15, to_date('2013-01-01','YYYY-MM-DD'), double to_date('2013-01-15','YYYY-MM-DD') - for agreement_id = 300

    );

    Query on table

    Ident_pk Ident_dtl_pk Effective_date Termination_date

    11013/01/0113/01/31
    11113/01/0113/01/30
    21213/01/0113/01/30
    21313/01/0113/01/15
    31413/01/0113/01/15
    31513/01/0113/01/15


    Result of the will

    Agreement_Id Ident_pk

    200                                        2

    300                                        3

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

    There is a single entry in ident against agreement_id and Ident_pk and if you can see that ident_pk is also present in the child table. My requirement is that at least 1 effective_date and child termination_date table must be match/equal to the parent table that is ident cov_effective_date and cov_termination_date against the same column of Ident_pk.

    for example:

    See the data in Ident_pk = 1, a = cov_effective_date 13/01/01 and its cov_termination_date = 13/01/31 and in the details table against column Ident_pk = 1, you can find that at lease 1 combinaisondes date match against Ident_pk = 1

    If you see Ident_pk = 2, then you can't find all the effective_date and termination_date against its corresponding cov_effective_date and termination_date Ident_pk...

    Same as 3

    -----------

    Summary is that there are date range in the ident against agreement_id and Ident_pk table and at least a range of dates even should be exist in detail table is ident_dtl against Ident_pk and if not then show that agreement_id and Ident_pk .

    I made this task using PL/SQL, but I think that there is a way to do the same task in SQL. Guide and if you have any questions then please let me know. Thank you

    Concerning

    Shu


    Hello

    To be considered as a football game, the same line in ident_dtl must have effective_date and termination_date correspondence?

    If so, a solution is:

    SELECT i.agreement_id

    i.ident_pk

    Ident I have

    LEFT OUTER JOIN ident_dtl d.ident_pk d = i.ident_pk

    AND d.effective_date = i.cov_effective_date

    AND d.termination_date = i.cov_termination_date

    WHERE d.ident_pk IS NULL

    ;

    Another pure SQL approach to such problems is to use an EXISTS subquery.

  • Interval data type

    Hi friends, could you please let me know how we can convert Fuego.lang.Interval data type value to Java.sql.Date in Oracle DB. Thanks, Luke

    Guess this should work: reportInitiationReviewDeadline-> Date_cible Java.Sql.Date data type Interval = new Java.Sql.Date (reportInitiationReviewDeadline.milliSeconds);

  • Extend a range of dates

    I have the following query, which works without problem. This will expand the range of dates, proof of identity, in a list of dates for me:
    SELECT     j_id
              ,  date_1
               + LEVEL
               - 1
                 datum
    FROM       (SELECT 123 j_id, TO_DATE('01/01/2012', 'DD/MM/YYYY') date_1, TO_DATE('31/01/2012', 'DD/MM/YYYY') date_2
                FROM   DUAL)
    CONNECT BY LEVEL <= (  date_2
                         - date_1
                         + 1);
    How can I do this for more than 1 sheet well? for example
    SELECT     j_id
              ,  date_1
               + LEVEL
               - 1
                 datum
    FROM       (SELECT 123 j_id, TO_DATE('01/01/2012', 'DD/MM/YYYY') date_1, TO_DATE('31/01/2012', 'DD/MM/YYYY') date_2
                FROM   DUAL
                UNION
                SELECT 456 j_id, TO_DATE('01/02/2012', 'DD/MM/YYYY') date_1, TO_DATE('29/02/2012', 'DD/MM/YYYY') date_2
                FROM   DUAL)
    CONNECT BY LEVEL <= (  date_2
                         - date_1
                         + 1);
    Thank you.

    Hello

    Here's one way:

    WITH   cntr          AS
    (
         SELECT     LEVEL - 1     AS n
         FROM     (
                  SELECT  MAX (date_2 - date_1)     AS max_dif
                  FROM    table_x
              )
         CONNECT BY     LEVEL <= 1 + max_dif
    )
    SELECT       x.j_id
    ,       x.date_1 + c.n
    FROM       table_x  x
    JOIN       cntr        c  ON  c.n <= x.date_2 - x.date_1
    ORDER BY  x.j_id
    ,            c.n
    ;
    

    If you do any filtering, it may be more effective to do this first. Start the WITH clause with a subquery that performs filtering, then use this result placed instead of your full table in the view online within the cntr as well as in the main query.
    For example:

    CREATE TABLE  table_x         AS
             SELECT 123 j_id, TO_DATE('01/01/2012', 'DD/MM/YYYY') date_1, TO_DATE('31/01/2012', 'DD/MM/YYYY') date_2
                FROM   DUAL
                UNION
                SELECT 456 j_id, TO_DATE('01/02/2012', 'DD/MM/YYYY') date_1, TO_DATE('29/02/2012', 'DD/MM/YYYY') date_2
                FROM   DUAL
    UNION         SELECT 999,          TO_DATE ('01/01/2013', 'DD/MM/YYYY'),     TO_DATE ('31/12/2013', 'DD/MM/YYYY')     FROM dual
    ;
    
    WITH     filtered_data     AS
    (
         SELECT     *
         FROM     table_x
         WHERE     date_1     < TO_DATE ('01/07/2012', 'DD/MM/YYYY')
    )
    ,        cntr          AS
    (
         SELECT     LEVEL - 1     AS n
         FROM     (
                  SELECT  MAX (date_2 - date_1)     AS max_dif
                  FROM    filtered_data
              )
         CONNECT BY     LEVEL <= 1 + max_dif
    )
    SELECT       f.j_id
    ,       f.date_1 + c.n
    FROM       filtered_data  f
    JOIN       cntr              c  ON   c.n  <= f.date_2 - f.date_1
    ORDER BY  f.j_id
    ,            c.n
    ;
    

    Published by: Frank Kulash, 27 January 2012 10:10
    Posted filtering example

  • How to get LASTDAY for each month between data dates...

    Hi friend

    I have a doubt, how to get LASTDAY for each month between data dates...

    for ex:
    My contribution will be like this
    date = 01/12/2011
    To date = 14/04/2011

    And I need an output like
    31/01/2011
    28/02/2011
    31/03/2011

    is it possible to achieve through sql query in oracle
    Thanks in advance for all friends to help him

    Hello

    Something like this (assuming that the dates are originally VARCHAR2s):

    SQL> var dt_start varchar2(10)
    SQL> var dt_end varchar2(10)
    SQL> exec :dt_start := '12-01-2011'
    
    PL/SQL procedure successfully completed
    
    SQL> exec :dt_end := '14-04-2011'
    
    PL/SQL procedure successfully completed
    
    SQL>
    SQL> select last_day(
      2           add_months(
      3             trunc(to_date(:dt_start,'DD-MM-YYYY'),'MM'),
      4             level-1
      5           )
      6         ) as result
      7  from dual
      8  connect by level <= months_between(to_date(:dt_end,'DD-MM-YYYY'), to_date(:dt_start,'DD-MM-YYYY'))
      9  ;
    
    RESULT
    -----------
    31/01/2011
    28/02/2011
    31/03/2011
     
    

    If the dates are already of the date data type, simply remove the to_date function.

  • SQL to generate the intervals from date of 6 months each, between two date ranges

    Hi all

    I looked in the forums, if someone uses CREATE_CHUNKS_BY_SQL for dates, but no luck.
    I want to update a table using pieces of dates.
    I need to generate date ranges to divide them by pieces.

    I have a table where I know that max (sales_date) and min (sales_date).
    Lets say max (sales_date): min (sales_date) 01/01/2008: 31/10/2010

    I want to break in intervals of 6 months (180 days) as below:
    chunk_id     start_date     end_date
    --------     ----------     --------
      1          01/01/2008     06/30/2008
      2          01/07/2008     12/31/2008
      3          01/01/2009     06/30/2009
      4          01/07/2009     12/31/2009
      5          01/01/2010     06/30/2010
      6          01/07/2010     10/31/2010
    He didn't exactly finish end of the month. Basically, I need these beaches of dates at apart 180 days.

    I appreciate if someone can throw some ideas on this.

    Thank you
    Raj.

    Hi, Raj,

    Sorry, it is unclear what you are asking.

    To generate a list of dates starting with min_sales_date and including all the 180 days after that up to (but not beyond) max_sales_date:

    WITH     got_params     AS
    (
         SELECT     DATE '2008-01-01'     AS min_sales_date
         ,     DATE '2010-10-31'     AS max_sales_date
         FROM     dual
    )
    SELECT     min_sales_date + (180 * (LEVEL - 1))     AS grp_start_date
    FROM     got_params
    CONNECT BY     LEVEL <= CEIL ( ( (max_sales_date - min_sales_date)
                                    + 1
                           )
                         / 180
                         )
    ;
    

    Output:

    GRP_START_D
    -----------
    01-Jan-2008
    29-Jun-2008
    26-Dec-2008
    24-Jun-2009
    21-Dec-2009
    19-Jun-2010
    

    December 16, 2010 is 180 days after June 19, 2010, but it is not displayed, because is after max_sales_date, which is 31 October 2010.

    I hope this helps you.
    Whenever you have any questions, post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data.

  • New in MapPoint. Can help you with the selection of a range of data?

    Hello

    I just open MapPoint 2013 as import data, select a radius from a given location and export data.  That's all I need of MapPoint to manage but can't seem to find a small tutorial on how to on this subject.

    I tried flying by the seat of my pants, so to speak and have selected a range of 70 minutes, but the output file shows only 96 files when I know that many more within a radius of driving I've selected.  Bugs appear to be associated with zip codes.  For example, in the Excel file there are no addresses (records) but only zip codes and a list indicating the number of organizations within each zip.  I want real organizations in a range of one hour.

    You can ask in the following forum because they are more likely to have relevant experts:

    Highway, streets and Trips, MapPoint .

  • Partitioning the table - range on data type (21, 7) number and varchar2

    Hello

    Database version:

    DB: Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    Operating system: HP - UX nduhi18 B.11.31 U ia64 1022072414 unlimited-license user

    APP: SAP - ERP

    I have to the partition of the RANGE on UPDATED_ON or PROFILE is a table that has a structure below:

    Name Null?    Type

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

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

    MANDT NOT NULL VARCHAR2 (9)

    MR_ID NOT NULL VARCHAR2 (60)

    PROFILE NON-NULL VARCHAR2 (54)

    NO_REGISTRE NOT NULL VARCHAR2 (30)

    INTERVAL_DATE NOT NULL VARCHAR2 (24)

    AGGR_CONSUMPTION NOT NULL NUMBER (21.6)

    MDM_VERS_NO NOT NULL VARCHAR2 (9)

    MDP_UPDATE_DATE NOT NULL VARCHAR2 (24)

    MDP_UPDATE_TIME NOT NULL VARCHAR2 (18)

    NMI_CONFIG NOT NULL VARCHAR2 (120)

    NMI_CONFIG_FLAG NOT NULL VARCHAR2 (3)

    MDM_DATA_STRM_ID NOT NULL VARCHAR2 (6)

    NSRD NOT NULL VARCHAR2 (24)

    REASON_CODE NOT NULL VARCHAR2 (9)

    QUALITY_FLAG NOT NULL VARCHAR2 (3)

    METHOD_FLAG NOT NULL VARCHAR2 (6)

    MSATS_UPDATE_DAT NOT NULL VARCHAR2 (24)

    MSATS_UPDATE_TIM NOT NULL VARCHAR2 (18)

    READ_STATUS NOT NULL VARCHAR2 (3)

    LEGACY_FLAG NOT NULL VARCHAR2 (3)

    CREATED_ON NOT NULL NUMBER (21.7)

    CREATED_BY NOT NULL VARCHAR2 (36)

    UPDATED_ON NOT NULL NUMBER (21.7)

    UPDATED_BY NOT NULL VARCHAR2 (36)

    CVERSNO NOT NULL VARCHAR2 (18)

    OLDER_MD_FLAG NOT NULL VARCHAR2 (3)

    TRANSACTION_ID NOT NULL VARCHAR2 (108)

    According to my knowledge, RANGE is better suited for the DATE or NUMBER. and partition INTERVAL is available on the DATE or number.

    PROFILE of column

    I havets is of type VARCHAR2. I know that again I can partition as Oracle convert internally to varchar2 in number when the data is inserted. But the INTERVAL is not possible.  However, so could you please suggest how RANGE partition on PROFILE?

    CREATED_ON column:

    It's the NUMBER with decimals. Could you guide me please?

    Please let me know if you need more information?

    See you soon

    Sameer

    I partitioned table as below:

    PARTITION BY RANGE

    (

    "CREATED_ON".

    )

    SUBPARTITION BY HASH

    (

    'PROFILE '.

    )

    SUBPARTITION TEMPLATE

    (

    TABLESPACE SUBPARTITION 'PROF_SUB01"'PSAPISU."

    TABLESPACE SUBPARTITION 'PROF_SUB02"'PSAPISU."

    TABLESPACE SUBPARTITION 'PROF_SUB03"'PSAPISU."

    TABLESPACE SUBPARTITION 'PROF_SUB04"'PSAPISU."

    TABLESPACE SUBPARTITION 'PROF_SUB05"'PSAPISU."

    TABLESPACE SUBPARTITION 'PROF_SUB06"'PSAPISU."

    TABLESPACE SUBPARTITION 'PROF_SUB07"'PSAPISU."

    TABLESPACE SUBPARTITION 'PROF_SUB08"'PSAPISU."

    TABLESPACE SUBPARTITION 'PROF_SUB09"'PSAPISU."

    TABLESPACE SUBPARTITION 'PROF_SUB10' 'PSAPISU '.

    )

    (

    "BEF12_CP00" VALUES LOWER PARTITION TO (20120101000000),

    "JAN12_CP01" VALUES LOWER PARTITION TO (20120201000000),

    "FEB12_CP02" VALUES LOWER PARTITION TO (20120301000000),

    "MAR12_CP03" VALUES LOWER PARTITION TO (20120401000000),

    "APR12_CP04" VALUES LOWER PARTITION TO (20120501000000),

    "MAY12_CP05" VALUES LOWER PARTITION TO (20120601000000),

    "JUN12_CP06" VALUES LOWER PARTITION TO (20120701000000),

    "JUL12_CP07" VALUES LOWER PARTITION TO (20120801000000),

    "AUG12_CP08" VALUES LOWER PARTITION TO (20120901000000),

    "SEP12_CP09" VALUES LOWER PARTITION TO (20121001000000),

    "OCT12_CP10" VALUES LOWER PARTITION TO (20121101000000),

    "NOV12_CP11" VALUES LOWER PARTITION TO (20121201000000),

    "DEC12_CP12" VALUES LOWER PARTITION TO (20130101000000),

    "JAN13_CP13" VALUES LOWER PARTITION TO (20130201000000),

    "FEB13_CP14" VALUES LOWER PARTITION TO (20130301000000),

    "MAR13_CP15" VALUES LOWER PARTITION TO (20130401000000),

    "APR13_CP16" VALUES LOWER PARTITION TO (20130501000000),

    "MAY13_CP17" VALUES LOWER PARTITION TO (20130601000000),

    "JUN13_CP18" VALUES LOWER PARTITION TO (20130701000000),

    "JUL13_CP19" VALUES LOWER PARTITION TO (20130801000000),

    "AUG13_CP20" VALUES LOWER PARTITION TO (20130901000000),

    "SEP13_CP21" VALUES LOWER PARTITION TO (20131001000000),

    "OCT13_CP22" VALUES LOWER PARTITION TO (20131101000000),

    "NOV13_CP23" VALUES LOWER PARTITION TO (20131201000000),

    PARTITION 'OTHER_CPMAX' VALUES LESS THAN (MAXVALUE)

    )

    works very well.

  • Catch the range of Date values

    Hi, guys.

    I need to check the date range that my product was available. You can use as a basis the values in the table below, but this structure can be modified to add all the things that could support the solution:

    ID_PRDCT DT_STRT DT_END
    1 20/01/25 12/01/12
    1 01/23/12-27/01/12
    1 26/01/30 12/01/12
    1 28/01/12-21/04/12
    1 20/04/12-25/05/12
    1 24/05/12-28/05/12
    1 26/05/12 05/29/12
    1 01/07/12-03/08/12
    1 01/08/12-16/08/12
    1 18/08/12-30/08/12
    1 01/12/12-31/12/12

    In this case, the result of my date range should be:

    1 20/01/12-29/05/12
    1 01/07/12-16/08/12
    1 18/08/12-30/08/12
    1 01/12/12-31/12/12

    Hello

    An the Heres how:

    WITH     got_new_grp          AS
    (
         SELECT     id_prdct, dt_strt, dt_end
         ,     CASE
                  WHEN  dt_strt <= MAX (dt_end)
                            OVER ( PARTITION BY  id_prdct
                                   ORDER BY      dt_strt
                             ROWS BETWEEN  UNBOUNDED PRECEDING
                                    AND      1          PRECEDING
                           )
                  THEN  0
                  ELSE  1
              END     AS new_grp
         FROM    t
    )
    ,     got_grp          AS
    (
         SELECT     id_prdct, dt_strt, dt_end
         ,     SUM (new_grp) OVER ( PARTITION BY  id_prdct
                                       ORDER BY          dt_strt
                           )         AS grp
         FROM    got_new_grp
    )
    SELECT       id_prdct
    ,       MIN (dt_strt)     AS grp_dt_strt
    ,       MAX (dt_end)     AS grp_dt_end
    FROM       got_grp
    GROUP BY  id_prdct
    ,            grp
    ORDER BY  id_prdct
    ,            grp
    ;
    

    This assumes dt_strt<= dt_end="" on="" every="">
    If you would care to post CREATE TABLE and INSERT statements for your sample data, then I could test it.

    You cannot use LAG or LEAD to see where each new group starts, because the order of the dt_strt is not the same as the order of the dt_end. In other words, if you ORDER BY dt_strt, two adjacent lines could be in the same group regardless of their values, because a previous line can have a dt_end, and as a result this line would be overlapp both of them. Similarly, if you ORDER BY dt_end, no matter what two adjacent lines contain, whether they are in the same group if som rank later has a sufficient dt_strt in advance.

  • How to get the number of days in a month of belonging to a range of dates

    Hi, I'm going crazy around a problem, I have 2 dates and one month I wanto to retrieve the number of days belonging to the months that fall within the range.

    for example:

    month of January 2011. begin_date = January 11, 2011, May 30, 2011 end_date result is 21
    month of January 2011. begin_date = December 11, 2010, result of end_date, January 10, 2011 10
    month January 2011 .begin_date = 2 February 2011, end_date may 25, 2011 result 0
    month of January 2011. begin_date = January 3, 2011, January 5, 2011 result DATE END 3

    and so on...

    I appreciate any suggestion
    Thank you


    Andrea

    Something like that... ?

    SQL> with t as
      2  (select  to_date('11/01/11','dd/mm/yy') from_dt,
      3           to_date('30/05/11','dd/mm/yy') to_dt,
      4           'Jan-11' mnth from dual)
      5  select least(last_day(to_date(mnth,'Mon-yy')),to_dt) -
      6         greatest(to_date(mnth,'Mon-yy'),from_dt) cnt
      7  from t  ;
    
           CNT
    ----------
            20
    

    If 0 is also expected...

    SQL> with t as
      2  (select  to_date('11/01/11','dd/mm/yy') from_dt,
      3           to_date('30/05/11','dd/mm/yy') to_dt,
      4           'Jan-11' mnth from dual union all
      5           select  to_date('11/01/11','dd/mm/yy') from_dt,
      6           to_date('30/05/11','dd/mm/yy') to_dt,
      7           'Jan-12' mnth from dual
      8           )
      9  select from_dt,to_dt,mnth,
     10         greatest(
     11              least(last_day(to_date(mnth,'Mon-yy')),to_dt)
     12              -
     13              greatest(to_date(mnth,'Mon-yy'),from_dt)
     14                 ,0) cnt
     15  from t;
    
    FROM_DT   TO_DT     MNTH          CNT
    --------- --------- ------ ----------
    11-JAN-11 30-MAY-11 Jan-11         20
    11-JAN-11 30-MAY-11 Jan-12          0
    

    Published by: JAC on February 9, 2012 19:22

Maybe you are looking for