Selection of records based on the flag

Hi all

I have records as follows:

Program name Effective_Date Valid_Flag
N 10/02/2012 ABCD
N 14/02/2012 ABCD
ABCD 20/02/2012 Y
N 01/03/2012 ABCD
N 10/03/2012 ABCD
ABCD 14/03/2012 Y
N 25/03/2012 ABCD
N 26/03/2012 ABCD
N 27/03/2012 ABCD
N 28/03/2012 ABCD
N 29/03/2012 ABCD
ABCD 25/04/2012 Y



I have to write a select statement to keep the first record and then only pull records when the Valid_Flag has changed. The result set should be as below.

Program name Effective_Date Valid_Flag
ABCD 10/02/2012 N - I kept the first record
20/02/2012 ABCD is - Valid_Flag chages to a Y for the first time and so on.
N 01/03/2012 ABCD
ABCD 14/03/2012 Y
N 25/03/2012 ABCD
ABCD 25/04/2012 Y

If there is no change in the flag, I don't have to draw from this record. Please help with suggestions of SQL. Thanks for your time and your help.

ssk1974 wrote:
Hi all

I have records as follows:

Program name Effective_Date Valid_Flag
N 10/02/2012 ABCD
N 14/02/2012 ABCD
ABCD 20/02/2012 Y
N 01/03/2012 ABCD
N 10/03/2012 ABCD
ABCD 14/03/2012 Y
N 25/03/2012 ABCD
N 26/03/2012 ABCD
N 27/03/2012 ABCD
N 28/03/2012 ABCD
N 29/03/2012 ABCD
ABCD 25/04/2012 Y

I have to write a select statement to keep the first record and then only pull records when the Valid_Flag has changed. The result set should be as below.

Program name Effective_Date Valid_Flag
ABCD 10/02/2012 N - I kept the first record
20/02/2012 ABCD is - Valid_Flag chages to a Y for the first time and so on.
N 01/03/2012 ABCD
ABCD 14/03/2012 Y
N 25/03/2012 ABCD
ABCD 25/04/2012 Y

If there is no change in the flag, I don't have to draw from this record. Please help with suggestions of SQL. Thanks for your time and your help.

In the future, it would be nice if you could provide the sample data as below, I created.

ME_XE?with data as
  2  (
  3     select 'ABCD' as col1, to_date('2/10/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
  4     select 'ABCD' as col1, to_date('2/14/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
  5     select 'ABCD' as col1, to_date('2/20/2012', 'mm/dd/yyyy')       as col2, 'Y' as col3    from dual union all
  6     select 'ABCD' as col1, to_date('3/01/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
  7     select 'ABCD' as col1, to_date('3/10/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
  8     select 'ABCD' as col1, to_date('3/14/2012', 'mm/dd/yyyy')       as col2, 'Y' as col3    from dual union all
  9     select 'ABCD' as col1, to_date('3/25/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
 10     select 'ABCD' as col1, to_date('3/26/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
 11     select 'ABCD' as col1, to_date('3/27/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
 12     select 'ABCD' as col1, to_date('3/28/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
 13     select 'ABCD' as col1, to_date('3/29/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
 14     select 'ABCD' as col1, to_date('4/25/2012', 'mm/dd/yyyy')       as col2, 'Y' as col3    from dual
 15  )
 16  select *
 17  from
 18  (
 19     select
 20             col1, col2, col3,
 21             lag(col3) over (partition by col1 order by col2 asc) as last_flag
 22     from data
 23  )
 24  where last_flag    != col3
 25  or    last_flag    is null;

COL1         COL2                       COL LAS
------------ -------------------------- --- ---
ABCD         10-FEB-2012 12 00:00       N
ABCD         20-FEB-2012 12 00:00       Y   N
ABCD         01-MAR-2012 12 00:00       N   Y
ABCD         14-MAR-2012 12 00:00       Y   N
ABCD         25-MAR-2012 12 00:00       N   Y
ABCD         25-APR-2012 12 00:00       Y   N

6 rows selected.

Elapsed: 00:00:00.08
ME_XE?

See you soon,.

Tags: Database

Similar Questions

  • Select a record based on the date field MAX

    I have the following query that works, but does include all the necessary columns.  I need to JOIN the run_events table, which is a child of the runroute table, such that I choose not only the run_code and max event_timestamp, but also the LATITUDE, LONGITUDE columns.  Each run_code has many events associated with it.

    Any help or pointers would be appreciated!

    Thank you

    I've included descriptions of output and query table

    WITH

    ETV as (select run_code

    -, LATITUDE, LONGITUDE

    max (event_timestamp) TS

    of run_events

    Run_code group

    )

    SELECT all THE RR.run_code,

    substr(PODDept.POD_NAME,1,10) DEPT,

    To_char (ETD ' HH: mi: SS AM') r_ETD,.

    To_char (ATD, ' HH: mi: SS AM') r_ATD,.

    substr (PODDest.POD_NAME, 1, 10) Dest,

    To_char (ETA, "HH: mi: SS AM'") r_ETA,.

    To_char (ATA, ' HH: mi: SS AM') r_ATA

    --        ,  VTE. LATITUDE, ETV. LONGITUDE

    to_char (VTE. TS, ' dd-mm-yyyy hh: mi: SS AM') TS

    OF routerun RR

    PADE LEFT JOIN PODDest ON RR. PODEST_CODE = PODDest.POD_ID

    LEFT JOIN PADE PODDept ON RR. PODEPT_CODE = PODDept.pod_id

    ETV LEFT JOIN ON RR.run_code = VTE.run_code

    WHERE ATA IS NULL

    ORDER BY RR. ETA, RR. RUN_CODE

    /

    SQL > @rpt_runroute.sql

    RUN_CODE DEPT R_ETD DEST R_ETA R_ATA TS R_ATD

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

    2013432247 NORFOLK 23:39:59 CHERRY PT 02:00 07/10/2013 01:00:15

    NEW YORK 20:45:03 2013432224 CRESCENT B 06:00 10/07/2013 12:52:28 AM

    2013432242 BALTIMORE 22:33:23 SALISBURY 10/07/2013 12:39:28 AM

    Descriptions of table

    PADE

    Name Null?    Type

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

    POD_ID NOT NULL NUMBER (10)

    POD_LONGITUDE NUMBER (10.6)

    POD_LATITUDE NUMBER (10.6)

    POD_NAME VARCHAR2 (64)

    ROUTERUN

    Name Null?    Type

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

    RUN_CODE NOT NULL VARCHAR2 (15)

    REMARKS VARCHAR2 (1024)

    PODEST_CODE NUMBER (10)

    PODEPT_CODE NUMBER (10)

    ETD                             DATE

    ATD                             DATE

    ETA                             DATE

    ATA                             DATE

    RUN_EVENTS

    Name Null?    Type

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

    RUN_CODE NOT NULL VARCHAR2 (15)

    EVENT_TIMESTAMP NOT NULL DATE

    EVENT_CODE NOT NULL VARCHAR2 (6)

    LONGITUDE NUMBER (10.6)

    LATITUDE NUMBER (10.6)

    Hello

    One way is to use the MAX function analytical rather than the MAX aggregate, like this:

    WITH

    ETV as (select run_code

    LATITUDE, LONGITUDE

    , event_timestamp-* ADDED *.

    , max (event_timestamp) OVER (PARTITION BY run_code)-* CHANGED *.

    as TS

    of run_events

    -Group by run_code-* REMOVED *.

    )

    SELECT all THE RR.run_code,

    substr(PODDept.POD_NAME,1,10) DEPT,

    To_char (ETD ' HH: mi: SS AM') r_ETD,.

    To_char (ATD, ' HH: mi: SS AM') r_ATD,.

    substr (PODDest.POD_NAME, 1, 10) Dest,

    To_char (ETA, "HH: mi: SS AM'") r_ETA,.

    To_char (ATA, ' HH: mi: SS AM') r_ATA - if ATA is NULL, what's the point?

    ETV. LATITUDE, ETV. LONGITUDE

    to_char (VTE. TS, ' dd-mm-yyyy hh: mi: SS AM') TS

    OF routerun RR

    PADE LEFT JOIN PODDest ON RR. PODEST_CODE = PODDest.POD_ID

    LEFT JOIN PADE PODDept ON RR. PODEPT_CODE = PODDept.pod_id

    ETV LEFT JOIN ON RR.run_code = VTE.run_code

    AND VTE.event_timestamp = VTE.ts-* ADDED *.

    WHERE ATA IS NULL

    ORDER BY RR. ETA, RR. RUN_CODE

    /

    If you would care to post, CREATE TABLE and INSERT statements for some sample data and the results you want from this data, then I could test it.

    What happens if there is a tie for the final event_timestamp (i.e. 2 or more lines with the same exct run_code and event_timestamp)?  You can use the analytic ROW_NUMBER function instead of MAX.

  • Poller DB to select records based on the timestamp

    Hi all

    I want select records from the coloumn timestamp where the timestamp is older than an hour. Is it possible to do this through poller db? I tried but unable to pass the dynamic value (currently - 1 hr)

    Thanks in advance!

    Eventually create a view based on the timestamp and singled out the dbpoller view.

  • unique several record based on the date record selection

    Hi experts,

    I have a table that contains multiple records for unique identification number now, I select the single record that contains the most recent date.

    Here is the structure

    Name of Type Null

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

    NUMBER OF ID_P

    NAME_P VARCHAR2 (12)

    DATE_P TIMESTAMP (6)

    Reviews

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

    1 loosi 22 August 13 01.27.48.000000000 PM

    1 hahahaha August 26, 13 01.28.10.000000000 PM

    KK 2 22 August 13 01.28.26.000000000 PM

    Emmeline 2 26 August 13 01.28.42.000000000 PM

    now I have to select below 2 lines how to write select qurie for this?

    1 loosi 26 August 13 01.27.48.000000000 PM

    Emmeline 2 26 August 13 01.28.42.000000000 PM

    Hello

    You can use the ROW_NUMBER analytic function.

    I don't have a copy of your table, so I'll use scott.emp to illustrate.  In scott.emp, there may be several lines for a single job.  To display only 1 row per job, hiredate line with the most recent:

    WITH got_r_num AS

    (

    SELECT empno, hiredate-, deptno, job or whatever columns you want

    ROW_NUMBER () taken OVER (PARTITION OF work

    ORDER BY hiredate DESC

    ) AS r_num

    FROM scott.emp

    -WHERE--if you need a filter put it here

    )

    SELECT *- or the list of all columns except r_num

    OF got_r_num

    WHERE r_num = 1

    ;

    What results do you want in the case of links?  Depending on your needs, you can add expressions of tiebreaker to the analytical ORDER BY clause or the use of RANK instead of ROW_NUMBER.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.
    If you change the query at all, post your modified version.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

  • Filter records based on the selection in adf 11.6

    Hello

    I have page, on the top section af:table displayed and tabs (af:showdetaiItem), in the section displayed below each tab having slumped workflow as a region (each workflow with the table)

    After selecting any line on table top, then should filter the corresponding records on table region taskflow I am able to get the selected value to the region through input parameters task flow.

    I have question concern, how to run the workflow after the selection of each row in the table? (see communication of the region)

    Please suggest good approach, as appropriate

    Thank you

    you are correct. by passage of parameter is an approach. Another approach is contextual event...

  • Delete records based on the foreign keys of oracle 11 g

    I have a requirement to remove the records from the tables in the order according to

    the existing foreign keys.

    I for example, the following tables and the pk, fk constraints:

    create table one

    (aa number (1),)

    descr varchar2 (20));

    ALTER table one

    Add constraint a_pk key (aa) primary;

    create table b

    (aa number (1),)

    descr varchar2 (20));

    ALTER table b

    Add constraint b_pk key (aa) primary;

    create table c

    (aa number (1),)

    descr varchar2 (20));

    ALTER table c

    Add constraint c_pk key (aa) primary;

    create table a2

    (aa number (2),)

    id_aa number (1).

    descr varchar2 (20));

    ALTER table a2

    Add constraint a2_pk key (aa) primary;

    ALTER table a2

    Add constraint a2_fk foreign key (id_aa)

    references a (aa);

    create table b2

    (aa number (2),)

    id_aa number (1).

    descr varchar2 (20));

    ALTER table b2

    Add constraint b2_pk key (aa) primary;

    ALTER table b2

    Add constraint b2_fk foreign key (id_aa)

    references b (aa);

    create table z

    (aa number (3),)

    id_aa number (1).

    id_bb number (1).

    descr varchar (20));

    ALTER table z

    Add constraint z_pk key (aa) primary;

    ALTER table z

    Add constraint z_fk1 foreign key (id_aa)

    references a (aa);

    ALTER table z

    Add constraint z_fk2 foreign key (id_bb)

    references b (aa);

    So, I want to choose the names of the tables in such an order so as

    deleting records will succeed...

    I built the following sql query (using the recursive subquery factoring):

    [p]

    with q (r_constraint_name, table_name, constraint_name, lvl) as

    (select table_name, constraint_name, r_constraint_name 1 lvl

    from user_constraints one

    where a.constraint_type = 'P '.

    Union of all the

    Select b.table_name b.constraint_name, b.r_constraint_name, q.lvl + 1 lvl

    from user_constraints b

    Join q

    on (q.constraint_name = b.r_constraint_name)

    where b.constraint_type = 'R '.

    )

    Select f.table_name, f.constraint_name, f.r_constraint_name, f.lvl

    q f

    [/ p]

    I want the results as the following list:

    Table-name

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

    B2

    A2

    Z

    A

    B

    C

    The table - B2, A2, Z - (in any order) must first referred in the list

    because they are based on the other three tables - A, B, C. Thus, in order to remove the

    A, B, C table records the B2, A2, table Z records must be beleted first.

    The query I posted above has the problem that it displays tables A2, B2 twice

    (1 because they have a pk and 2 because they have fk referring A, B relatively tables).

    Is there a solution for this problem?

    Note: I use db11g v2

    I wrote not all relationships of tables user_constraints (only argument constraint_name = r_constraint_name)

    Thank you

    SIM

    I have a requirement to remove the records from the tables in the order according to

    the existing foreign keys.

    . . .

    The table - B2, A2, Z - (in any order) must first referred in the list

    because they are based on the other three tables - A, B, C. Thus, in order to remove the

    A, B, C table records the B2, A2, table Z records must be beleted first.

    Is there a solution for this problem?

    Yes - the 'solution' is to use ON DELETE CASCADE, as appropriate or write a procedure that removes tables in the proper order.

    The solution is NOT to try to use dynamic sql statements to do so.

    You already know the good parent/child relationships. Simply create a procedure that uses the correct order.

    Analyses are necessary in any case to determine the proper order AND press the appropriate values to use to remove the appropriate lines

    Your DDL for tables and constraints must be in a version control system

    Update the procedure when / if new constraints or tables are added to the application

    IMHO, you must use dynamic SQL NOT to try to adjust automatically if a new constraint appears. New constraints should not appear by accident - they appear ONLY as part of a well planned release.

  • Retention of records based on the end of the calendar year

    Content using WebCenter 11 g and Records Management, I'm looking for a way to create a rule of provision based on the end of a calendar year.  For example, the rule might wait two years after the end of the calendar year in which the content item has been published.  Does anyone know how to do this?  I'm looking for something that is easy to maintain, but right now my best option is to create a metadata field to end of calendar year and then do a little iDoc script to set point which is archived for each content.  I would really like to avoid this if possible.  Any ideas?

    I think what you're trying to do is to "synchronize on the period start date.  It is part of the definition of the trigger.

    http://docs.oracle.com/cd/E21764_01/doc.1111/e10640/e01_interface.htm#RMDSG620.

    Assuming that the trigger is based on the release date:

    -An item is activated in June 30, 2016.

    -After the date of recording, wait two years.  This makes the eligible trigger on June 30, 2018.

    - But you want to wait until the end of 2018 to make available.

    -Check the above mentioned framework would force alienation to fire on January 1, 2019, instead of June 30, 2018.

  • Deleting record based on the ID of the main table

    Hello
    SQL> desc news
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     NEWS_ID                                   NOT NULL NUMBER(14)
     NEWS_DATE                                          TIMESTAMP(0)
     SL_ID                                              NUMBER(2)
     HEADING                                            VARCHAR2(3120)
     DESCRIPTION                                        VARCHAR2(3900)
    
    SQL> desc news_location
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     NEWS_ID                                            NUMBER(14)
     COUNTRY                                            VARCHAR2(32)
     REGION                                             NUMBER(2)
    
    SQL> desc news_product
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     NEWS_ID                                            NUMBER(14)
     PRODUCT_CATEGORY_ID                       NOT NULL NUMBER(14)
     PRODUCT                                            VARCHAR2(27)
    
    SQL> desc news_service
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     NEWS_ID                                            NUMBER(14)
     SERVICE_ID                                NOT NULL NUMBER(14)
     SRVIS                                              VARCHAR2(16)
    
    SQL> desc news_info
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     NEWS_ID                                            NUMBER(14)
     SOURCE                                             VARCHAR2(203)
     ORIGIONAL_NEWS                                     VARCHAR2(3900)
     HEADING                                            VARCHAR2(3110)
    
    SQL> select count(*) from news where TO_CHAR(news_date,'YYYY') <  2012;
    
      COUNT(*)
    ----------
          8759
    I am trying to remove the news that are published before 2012, but the tables in detail consists the notebook of the child based on the news_id has been. Request certainly simple deletion will not work

    Please advise and thank you in advance

    Once again, I tell you, do not need ON DELETE CASCADE in the Delete query.

    Just use the Delete query like: -.

    delete from news where TO_CHAR(news_date,'YYYY') <  2008;
    

    And the child tables are deleted as a result.

  • Need to set the attribute of the current record based on the value of the next record

    With the help of forms 6, I have a form that displays the list of folders. There may be multiple records with the same ID, but with different expiration dates. I need set attributes for hilite only the record with the latest expiration date. The current list points of interest reviews of future expiration dates - but we found that, sometimes, the subscription is renewed before the expiration date has been reached, causing two records with the same ID with expiry dates in the future.

    I can (and do) sort the records by date of expiry and the identification for the record with the latest expiration date is always the last to this ID, so what I want to do is to check the next record to see whether or not it has a different ID. If the current record is the last expiration date, & must be hilited. Because I might want to hilite the current record, I can't simply navigate to another record, according to the description I found, what makes the next_record builtin. Anyone know how I can check for a value in the next record without making the current record?

    Thank you.

    What I would do:

    -Create a DB view based on your table and including the function call DRIVE as a separate column.
    -Base that block you on this point of view
    -If the block is modifiable, set the DML target for the block to your database table.

  • By selecting certain records by using the check box

    Hello

    I have a similar problem mentioned in this thread Re: select specific records using the checkbox I got if I have only one primary key value in the work table. I don't know how to handle it when I have several primary keys of the table I want to use for filtering?

    Thank you.

    Hello

    You can use rowid
    First report

    SELECT APEX_ITEM.CHECKBOX(1,e.rowid) chk,
    e.*
    FROM emp e
    

    Use even submit after processes.
    And target page report

    SELECT e.*
    FROM emp e
    WHERE EXISTS(
    SELECT 1
    FROM apex_collections c
    WHERE c.collection_name = 'P46COL'
    AND c.c001 = e.rowid)
    

    Kind regards
    Jari

    Published by: jarola on October 14, 2010 10:50

  • Display values based on the flag

    Oracle 10g version

    Hi I have a model in a variable and I need display or hide some lables based on certain values.
    I have an example below .copying the output from the example below.
    I love lables I need to show or hide based on the values of the label. Please let me know the solution...
    /* Formatted on 2010/07/08 20:50 (Formatter Plus v4.8.8) */
    set serveroutput on;
    DECLARE
       v_content   VARCHAR2 (4000);
       v_mflag      VARCHAR2 (1)    := 'N';
       v_cflag      VARCHAR2 (1)    := 'Y';
       v_template   varchar2(4000)   := 
                                           'Date            :mail_dt
                                            Dear            :cust_name
                                            Request Number  :vzb_track_no
                                            Order Number    :ord_no
                                            Order Activity  :ord_activity
                                            Product         :prduct
                                            Managed         :managed
                                            Cpe             :cpe_ord';
    BEGIN
       v_content := replace(replace(replace(replace(replace(replace(replace(replace(v_template,
                ':mail_dt',sysdate),
                ':cust_name','Steven'),
                ':vzb_track_no','ABC123'),
                ':ord_no','XYZLKJHGVC'),
                ':ord_activity','Assigned'),
                ':prduct','Phone'),
                ':managed',v_mflag),
                ':cpe_ord',v_cflag);
                dbms_output.put_line(substr(v_content,1,254));
                dbms_output.put_line(substr(v_content,255,499));
    END;
    Out put
    Date                    08-JUL-10
    Dear                    Steven
    Request Number   ABC123
    Order Number      XYZLKJHGVC
    Order Activity      Assigned
    Product              Phone
    Managed            N    -- i dont need this row
    Cpe                   Y         

    new learner wrote:
    Out put

    Date                    08-JUL-10
    Dear                    Steven
    Request Number   ABC123
    Order Number      XYZLKJHGVC
    Order Activity      Assigned
    Product              Phone
    Managed            N    -- i dont need this row
    Cpe                   Y         
    

    You can strip the line before the declarations to REPLACE;

    DECLARE
       v_content   VARCHAR2 (4000);
       v_mflag      VARCHAR2 (1)    := 'N';
       v_cflag      VARCHAR2 (1)    := 'Y';
       v_template   varchar2(4000)   :=
    'Date            :mail_dt
    Dear            :cust_name
    Request Number  :vzb_track_no
    Order Number    :ord_no
    Order Activity  :ord_activity
    Product         :prduct
    Managed         :managed
    Cpe             :cpe_ord';
    BEGIN
       if v_mflag = 'N' then
         v_template := regexp_replace(v_template,chr(10)||'.*:managed');
       end if;
       v_content := replace(replace(replace(replace(replace(replace(replace(replace(v_template,
                ':mail_dt',sysdate),
                ':cust_name','Steven'),
                ':vzb_track_no','ABC123'),
                ':ord_no','XYZLKJHGVC'),
                ':ord_activity','Assigned'),
                ':prduct','Phone'),
                ':managed',v_mflag),
                ':cpe_ord',v_cflag);
       dbms_output.put_line(v_content);
    END;
    /
    
    Date            10-07-08
    Dear            Steven
    Request Number  ABC123
    Order Number    XYZLKJHGVC
    Order Activity  Assigned
    Product         Phone
    Cpe             Y
    
  • Select records based on the monthly anniversary date

    Hello

    I have a table with a field of date_added and I want to select records from monthly birthday of this field.

    for example. ID, Date_added
    1, DECEMBER 10, 2012
    2, 11 NOVEMBER 2012
    3, 10 MARCH 2012
    4, FEBRUARY 28, 2012
    5, 30 DECEMBER 2012

    So for January 10, 2013, I would like to return the documents 1 and 3 only

    I started watching the extract function, but this little falls down to the records at the end of the month. For example, on 28 February, I also include records where 29, 30 or 31 is the day of date_added. So, in the above table, I won't return documents 4 and 5, but retrieves only returns 4.

    Is there a simple function to make the request of birthday this month - have I missed something very obvious? Or I have to write a query to explicitly dates at the end of the month? So far I have not found a reasonable solution!

    I use 11g

    Thank you

    user11259857 wrote:
    Hi Al,.

    No I don't think that there is a flaw. For example, the 30 Jan is not the last day of the month, but is June 30. Thus, on 30 January I want only to interrogate all the dates falling on the 30th - 28 February, after already being interrogated on the 28 Jan. However, on 30 June, I would query the 30th of each month, as well as the 31 January, March, may, July, Aug, Oct, dec. February is a special case, being both shorter and a leap year

    Thank you

    Richard

    Hi Richard,

    so, we can assume that your needs are:

    If the day is the last day of that month, interview the day of the other months being > = day of the current month.

    That is to say:

    Jan-30 = query only 30 other months
    Jan-31 = query only 31 of the other months

    Feb-28 (non-leap years) = question 28, 29, 30 and 31 other months
    29 February (leap year) = query 29,30,31 to other months

    Mar-30 = query only 30 other months
    Apr-30 = query 30 and 31 other months

    This hypothesis is correct?

    If so, then something like this should work:

    WITH mydates(id, date_added) AS
    (
       SELECT 1, TO_DATE('10-DEC-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL
       SELECT 2, TO_DATE('11-NOV-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL
       SELECT 3, TO_DATE('10-MAR-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL
       SELECT 4, TO_DATE('28-FEB-2012', 'DD-MON-YYYY') FROM DUAL UNION ALL
       SELECT 5, TO_DATE('30-DEC-2012', 'DD-MON-YYYY') FROM DUAL
    )
    SELECT id, date_added
      FROM mydates
     WHERE (:input_date = LAST_DAY(:input_date) AND TO_CHAR(:input_date,'DD') <= TO_CHAR(date_added, 'DD'))
        OR TO_CHAR(:input_date,'DD') = TO_CHAR(date_added, 'DD');
    
    with input_date = 28/02/2013
    
    id   date_added
    4    28/02/2012
    5    30/12/2012
    

    Kind regards.
    Al

    Published by: Alberto Faenza on 10 January 2013 15:21
    Added example

  • Select records based on the value

    Hello

    I have a table with 3 fields,
    WITH t1 AS(SELECT 'P1' po_number,'R1' route_id,1900 route_cost FROM dual
    UNION ALL SELECT 'P1','R2',2300 FROM dual
    UNION ALL SELECT 'P1','R3',1100 FROM dual
    UNION ALL SELECT 'P2','R7',1200 FROM dual
    UNION ALL SELECT 'P2','R8',4500 FROM dual)
    SELECT * FROM T1
    
    PO_NUMBER     ROUTE_ID     ROUTE_COST
    P1     R1     1900
    P1     R2     2300
    P1     R3     1100
    P2     R7    1200
    P2     R8    4500
    and I want to choose single route_id for a po_number where the cost is high
    and my output should be
    PO_NUMBER     ROUTE_ID     ROUTE_COST
    P1     R2     2300
    P2     R8     4500
    Thank you
    San

    Published by: sandeep9 on April 9, 2011 04:22
    WITH t1 AS(
               SELECT 'P1' po_number,'R1' route_id,1900 route_cost FROM dual UNION ALL
               SELECT 'P1','R2',2300 FROM dual UNION ALL
               SELECT 'P1','R3',1100 FROM dual UNION ALL
               SELECT 'P2','R7',1200 FROM dual UNION ALL
               SELECT 'P2','R8',4500 FROM dual
              )
    SELECT  po_number,
            max(route_id) keep(dense_rank last order by route_cost) route_id,
            max(route_cost) route_cost
      FROM  T1
      GROUP BY po_number
    /
    
    PO RO ROUTE_COST
    -- -- ----------
    P1 R2       2300
    P2 R8       4500
    
    SQL> 
    

    SY.

  • Selection of Inspection based on the attributes of the image

    I'm processing the stored images and must choose an inspection based on attributes of the image as the name and the size (length in pixels).

    Currently, I do all this in only one inspection, but since I'm inspecting several product families (differentiated my name of the image), and several sizes for each family, my inspection algorithm becomes very difficult to manage, so I would like to create a supervisor application that can determine which family of products and the size I'm looking, and then run the corresponding inspection and then do some data sharing and saving the image and loop back to the next image.

    I played with the ability to select Inspection in VBAI, but since I'm not on the material or communications to select the inspection, I can't seem to find a viable solution, ideally, I would like to go through the step of configuration once, then jump to the state diagram for the treatment of the initial image (determine the product family and size) then go to 'Select Inspection' and run the corresponding inspection.  This is where I'm stuck, IE., how to trigger the jump to select inspection in the state diagram?  Some people I have consulted so far say: you can't do that!  Anyone beg to differ?

    If I can't access select Inspection of state diagram, then plan B is to use the LabView API and make the principal contractor in LabView, it is where I need to go?

    Thank you

    Eric

    If you have the indicator Activate Product select enabled, select product State will run automatically after the State inspect goes to terminal completion. You can use a VI select LabVIEW Run in the State of product for your logic and move to the next round to load. With Vision Builder AI 2010, this path can be considered to be the real path to the inspection (inspection select dynamically run then) so you do not preconfigure a lookup table of inspections to run with values (it was the previous way of doing and it does not allow to dynamically load new inspections that weren't in the preconfigured table). Don't know how it works with your system, but using the LabVIEW API is an alternative that would give you better control and. You might even have a stage run a LV VI specify the control to use on an iteration in Prioduct selection state and inspection of logging of data/images to use later, but due to the opening and closing of the inspections overload new inspections may make having an inspection separate for logging of common data/images does not not your needs timing.

    Hope this helps,

    Brad

  • Restrict the records based on the condition

    Select * from EMP where deptno = 10;

    O/P:

    7782CLARKMANAGER7839JUNE 9, 81245010
    7839KINGPRESIDENTNOVEMBER 17, 81500010
    7934MILLERCLERK7782JANUARY 23, 82130010

    But I need 1 sheet with as described in condition.

    If JOB = 'MANAGER' pick this record

    If is not available, then choose JOB = 'PRESIDENT' record

    If is not available, then choose JOB = ' ' record

    A way

    Select * from)

    Select

    EmpNo

    ename

    work

    Manager

    hire_date

    salary

    deptno

    , rank() over (stopped in case of job when = "MANAGER", 1).

    When job = 'PRESIDENT' then 2

    When job = 'CLERK' then 3

    4 something else

    end

    ) rnk

    from EMP

    where deptno = 10

    )

    where rnk = 1

    If there is more than a Manager for example, the result would be more than one line.

    If you don't want that one line in these cases use row_number instead of rank.

    In this case, you want to refine the order by clause probably.

Maybe you are looking for