Retrun separate lines with duplicate values

Hello

I have the columns id, addr1, addr2, city and State of coding. I need to know all the coding IDS that have the same addresses and at the same time filter out the same side of the id of the request.

For example:

acctid addr1, addr2 City State

WEF 1 101 101 sd

1                         101          wef     sd

WEF 2 101 101 sd

WEF 3 101 101 sd

DC 4 102 102 homeless

From the above data, I want to get filter tier 4 and get lines 1, 2 and 3. How to achieve with a sql query

Thank you

Arch

Wrong forum!

This forum is ONLY for sql developer questions.

Please mark the thread ANSWERED and repost it in Sql and PL/SQL forum.

SQL and PL/SQL

Tags: Database

Similar Questions

  • Updated several lines with different values

    Hello!
    I have a problem. I need to update more than 1000 lines with different values. How can I do?
    For exsample I have table:
    ID; color, date,
    1 red
    2 green
    3 white

    I need to update the date field.

    Update table
    Set date = '01.02.03'
    where id = 1

    Update table
    Set date = '01.03.03'
    where id = 2


    Maybe it's how to update multiple rows in a single request?

    Sorry for my bad English.
    Thank you!

    Hello

    You can try this

    UPDATE TABLE SET DATE = CASE
                        WHEN ID = 1 THEN TO_DATE('01-02-03','DD-MM-RR')
                        WHEN ID = 2 THEN TO_DATE('01-03-03','DD-MM-RR')
                        END
    

    see you soon

    VT

  • How to display the line empty as a line with null values

    Hi all

    Pls advise me if it is possible to use a single query statement to display
    Empty row (i.e. not a single return line) as a line with null values.

    For example,.

    Select the names of names_mst whose name = "sgasfgs".

    Result:
    Names of
    =====
    < null >

    Hello
    If you desire to join external to double, as shown below, you still get at least a line of production

    SELECT  nm.names
    FROM            dual
    LEFT OUTER JOIN names_mst   nm  ON nm.name='sgasfgs';
    
  • Pulling on the first line with a value of repetition

    Hello
    We use the Oracle 11.1.

    We have a table of postal codes.

    We have several lines for each zip code because we have different areas that use the same zip code.

    We want to reduce the lines of a line by zip code. But they said use they want to keep the fields that differ (neighborhood of the exodus).

    Then they said "Just take the first value of each."

    This code reduces the postcodes of a line by postal code, but as you can see I replaced the field with the name of the field values.
    SELECT distinct  ZIPCODE, CITY, STATE, COUNTY, AREACODE, 'CITYTYPE', CITYALIASABBREVIATION, 'CITYALIASNAME', LATITUDE, LONGITUDE, TIMEZONE, ELEVATION, COUNTYFIPS, DAYLIGHTSAVING, PREFERREDLASTLINEKEY, CLASSIFICATIONCODE,
               MULTICOUNTY, STATEFIPS, 'CITYSTATEKEY', 'CITYALIASCODE', 'PRIMARYRECORD', CITYMIXEDCASE, 'CITYALIASMIXEDCASE', STATEANSI, COUNTYANSI
        FROM   zip_code
    GROUP BY   ZIPCODE, CITY, STATE, COUNTY, AREACODE, CITYTYPE, CITYALIASABBREVIATION, LATITUDE, LONGITUDE, TIMEZONE, ELEVATION, COUNTYFIPS, DAYLIGHTSAVING, PREFERREDLASTLINEKEY, CLASSIFICATIONCODE, MULTICOUNTY, STATEFIPS,
               CITYALIASCODE, PRIMARYRECORD, CITYMIXEDCASE, STATEANSI, COUNTYANSI
    order by zipcode; 
    How should I take either one record per postal code with the first value in these fields or

    How should I take the first record for each zip code?

    either way works for me.

    Thank you

    Hello

    This is called a Query Top - N , and this is a way to do it:

    WITH     got_r_num     AS
    (
         SELECT     z.*
         ,     ROW_NUMBER () OVER ( PARTITION BY  zipcode
                                   ORDER BY          city
                             ,                ...   -- add tie-breakers here
                           )      AS r_num
         FROM    zip_code
    )
    SELECT     *     -- or list all columns except r_num
    FROM     got_r_num
    WHERE     r_num     = 1
    ;
    

    You can simply use MIN or MAX on the columns, as the line with the name of the minimum city do not lowest have area code or the longitude. The above method preserves the first line of each zip code intact, where the 'first': the first in order of aphabetic by the name of the city. If it is not unique, then you may want breakage to the analytical ORDER BY clause.

    If you are deleting rows, you can use this in a NOT IN subquery. If you copy lines to a new table, you can use the query above in an INSERT statement.

    Published by: Frank Kulash, March 18, 2011 12:40

    I just see Polywog response:

    Pollywog wrote:
    You can use the rank or rownumber function...

    If I understand the problem, you don't want to use RANK in this particular case. When there is equality, GRADE will assign 1 to all the contenders. I think the whole point of this thread is that you exactly want a #1 in each zip code, which is what ROW_NUMBER, but not RANK, guarantees.

  • Add filter slot table form to show the lines with null values

    Hello

    I have a tabular presentation where we need to add a filter with two values (selection list) so that if one of the columns in a table (column1) is zero, then I need to display all records where column1 is null.

    I was wondering how do I put this in the Source of tabular forms where condition. This filter has only two values,

    All the
    NULL for the error

    So when the user selects all, then all the records in the table are shown
    If the user selects 'Value Null in error', while the records where Column1 is null will be shown

    For example
     column1        column2
                           A
                           B
          1               C
          3               D
     
    If the user selects, then

    all four files will show up. Else, only the first and the second will be returned.

    Thank you

    Hi, Ryan.

    Try a static LOV like this

    STATIC2:;,--- All ---;--- All ---
    

    and a Where clause, like this

    where column1 is null or :p1_filter like '%%'
    

    Jeff

  • Adding a UNIQUE CONSTRAINT to an existing column with duplicate values

    Oracle Forums Hello, I have a table that contains rows 11 901. I tried to define the UNIQUE constraint on the column of xcode, but encountered an error: the column already contain duplicates! I rescued following SQL 'SELECT COUNT (*) FROM States;' the result is 11 901 and 'SELECT COUNT (DISTINCT (xcode)) FROM States;' the result is 11 680. So to enforce this unique key I have to remove the 221 lines. Please how can I do this?

    REMOVE duplicates...

    For example, as

    delete from your_table t
    where rowid <
       (
       select max(rowid)
       from your_table r
       where t.unique_column = r.unique_column);
    

    Thne create the constraint.

  • Get line with max value

    Hi all

    I have a table

    Amount Line_num
    1 10
    2 20
    3 30

    create table Test (number line_num, quantity number);
    Insert into test values (1,10);
    Insert into test values (2.20).
    Insert into test values (3.30);

    I need to get the line number that has a maximum amount.

    Help, please.

    Thank you

    Anatoliy
    select
      max(line_num) keep (dense_rank last order by amount) m
    from test
    
    M
    3
    

    concerning

  • Ridge line with default values

    Hi friends I am using JDeveloper 11.1.1.3.I want to create a new line in a table .but this line must have some default values. As an attribute username, still need to show a default name. I need to write the ViewImpl method.

    According to [url http://download.oracle.com/docs/cd/E17904_01/apirefs.1111/e10653/oracle/jbo/server/ViewRowImpl.html#create (oracle.jbo.AttributeList documentation)] the, really want to do this by overriding the method create of the ViewRowImpl class (that is, assuming that in the VO is the right place).

    The Fusion developer [url http://download.oracle.com/docs/cd/E17904_01/web.1111/b31974/bcrules.htm#sthref794] Guide also shows you how to proceed at the level of the OS

    John

  • generate the view in line with the values of the 'sequence' 0.36

    I want my query to join inline view that has values of 0.36, what is the best way to create this inline-view?
    My initial solution would be:
    SELECT LEVEL RESULT FROM Dual CONNECT BY LEVEL < 37
    union
    select 0 from dual
    order by 1
    I want to write the query that returns the same values as this query, I showed.

    CharlesRoos wrote:
    I want my query to join inline view that has values of 0.36, what is the best way to create this inline-view?
    My initial solution would be:

    SELECT LEVEL RESULT FROM Dual CONNECT BY LEVEL < 37
    union
    select 0 from dual
    order by 1
    

    I want to write the query that returns the same values as this query, I showed.

    SELECT (LEVEL - 1) RESULT FROM Dual CONNECT BY LEVEL <= 37 ;
    

    Published by: user503699 on October 29, 2010 14:20

  • How to return a single LINE with Multiple value separated by a colon in a SQL query

    Hello

    I have a SQL, as shown.
    select deptno
      from dept
    I want to mofidfy this query, so that it should return me departments with colon delimeted list in a ROW.
    10:20:30:40.......
    Thank you
    Deepak
  • Need to separate lines, with the help of the distinct clause

    I have according to requirement

    Organization of end startdate EmpID
    1 O1 from January 1, 2008
    2 on January 2, 2008 July 31 08 O1
    3 2 January 2008 31 July 08 O1
    4 2 January 2008 31 July 08 O2
    5 2 January 2008 31 July 08 O2
    6 2 January 2008 31 July 08 O2
    7 2 January 2008 31 July 08 O3
    8 2 January 2008 31 July 08 O3


    My requirement is to get a sql query which report me something like that

    Organization of end startdate EmpID
    1 O1 from January 1, 2008
    4 2 January 2008 31 July 08 O2
    7 2 January 2008 31 July 08 O3

    Any empid, startdate, which is fine for a given organism (IE organization should be separate)

    concerning
    Vikas

    Published by: user634784 on January 19, 2009 04:05

    In reality... N °

    Sure about that?

    SQL>  select organisation,
      2     min(startdate) keep(dense_rank first order by empid asc) startdate,
      3     min(enddate) keep(dense_rank first order by empid asc) enddate,
      4     min(empid) keep(dense_rank first order by empid asc) empid
      5     from t
      6    group by organisation
      7  /
    
    OR STARTDATE ENDDATE        EMPID
    -- --------- --------- ----------
    O1 01-JAN-08                    1
    O2 05-JAN-08 31-JUL-08          4
    O3 02-JAN-08 31-JUL-08          7
    
  • Query generates duplicate values in successive lines. I can null out them?

    I have had very good success (thanks to Andy) to obtain detailed responses to my questions posted, and I wonder if there is a way in a region report join query that produces lines with duplicate values, I cannot suppress (replace) printing of duplicate values in successive lines. In the event that I managed to turn the question into a mess unintelligible (one of my specialities), let me give an example:

    We try institutions undergraduate that an applicant has participated in the list and display information on release dates, gpa and major (s) / according to decision-making. The problem is that there may be several major (s) / minor (s) for a given undergraduate institution, so the following is produced by the query:

    Knox College hard 01/02 01/06 4,00 knitting
    Knox College hard 01/02 01/06 4,00 cloth repair
    Advanced University 02/06 01/08 3.75 Clothing Design
    Really advanced U 02/08 01/09 4,00 sportswear
    Really advanced U 02/08 01/09 4,00 basketball burlap

    I want it to look like this:

    Knox College hard 01/02 01/06 4,00 knitting
    Tissue repair
    Advanced University 02/06 01/08 3.75 Clothing Design
    Really advanced U 02/08 01/09 4,00 sportswear
    Burlap tennis shoe

    * (Edit) Please note that the repair of fabric and lines tennis shoe repair should be positioned properly in a table, but unfortunately had space here for a reason suppresed any. *

    Under the tuteage of Andy, I would say the answer is probably javascript one loop in the DOM, you are looking for the innerHTML of specific TDs in the table, but I want to confirm that, or Apex provides it a box I can check which will produce the same results? Thanks to the guy to advance and sorry for all the questions. We were charged to use Apex for our next project and learn it using it, as the training budget is non-existent this year. I love ;) unfunded mandates

    Phil

    Published by: Phil McDermott on August 13, 2009 09:34

    Hi Phil,

    JavaScript is useful, because the feature break column in the report attributes (which would be my first choice if poss).

    If you need to go beyond 3 columns, I would say something in the SQL statement itself. This means that the sort would probably have to be controlled, but it is doable.

    This is a pretty old thread on the subject: Re: grouping reports (non-interactive) -with an example here: [http://htmldb.oracle.com/pls/otn/f?p=33642:112] (I used a custom template for the report, but you don't need to go that far!)

    This uses the features of LAG in SQL to compare the values on line for values on the line before - ability to compare these values allows you to determine which ones to show or hide.

    Andy

  • two rows of delete with different values

    Hello

    I wouldn't lines with the same id and have values of E and F 10258932.

    I would like the following data:
    A        B  C      D     E N
    -------- -- ------ ----- - -
    10258927 1  103,35 0
    10258929 3  284,85 89,52 E N
    10258929 4  323,85 89,52 E N
    10258930 5  478,80 91,53 E N
    10258931 6  436,67 78,09 E N
    But I have the following lines:
    SQL> with my_table as
      2  (
      3  select '10258927' a, '1'  b, '103,35'  c, '0'      d,   NULL  e from dual union all    
      4  select '10258928' a, '2'  b, '0'       c, '15,19'  d,  'E'    e from dual union all
      5  select '10258929' a, '3'  b, '284,85'  c, '89,52'  d,  'E'    e from dual union all
      6  select '10258929' a, '4'  b, '323,85'  c, '89,52'  d,  'E'    e from dual union all
      7  select '10258930' a, '5'  b, '478,80'  c, '91,53'  d,  'E'    e from dual union all
      8  select '10258931' a, '6'  b, '436,67'  c, '78,09'  d,  'E'    e from dual union all
      9  select '10258932' a, '7'  b, '784,88'  c, '23,19'  d,  'E'    e from dual union all
     10  select '10258932' a, '8'  b, '100,88'  c, '11,11'  d,  'E'    e from dual union all
     11  select '10258932' a, '9'  b, '300,88'  c, '22,22'  d,  'F'    e from dual union all
     12  select '10258932' a, '10' b, '468,25'  c, '78,33'  d,  'F'    e from dual)
     13  select a, b, c, d, e, no_ds from
     14  (
     15    select a, b, c, d, e,
     16           case when c > 0 and e != 'F'
     17                then 'N'
     18           end no_ds
     19    from my_table)
     20  where no_ds = 'N' or e is null
     21  order by 1
     22  /
    
    A        B  C      D     E N
    -------- -- ------ ----- - -
    10258927 1  103,35 0
    10258929 3  284,85 89,52 E N
    10258929 4  323,85 89,52 E N
    10258930 5  478,80 91,53 E N
    10258931 6  436,67 78,09 E N
    10258932 7  784,88 23,19 E N
    10258932 8  100,88 11,11 E N
    
    7 Zeilen ausgewählt.
    
    SQL> 
    Does anyone have an idea?

    Oh, I read the title again once: 'remove double lines with different values.
    If it means that he is not specifically E and F values, but only if there is more than one distinct value, then you can do the following:

    with my_table as
    (
    select '10258927' a, '1'  b, '103,35'  c, '0'      d,   NULL  e from dual union all
    select '10258928' a, '2'  b, '0'       c, '15,19'  d,  'E'    e from dual union all
    select '10258929' a, '3'  b, '284,85'  c, '89,52'  d,  'E'    e from dual union all
    select '10258929' a, '4'  b, '323,85'  c, '89,52'  d,  'E'    e from dual union all
    select '10258930' a, '5'  b, '478,80'  c, '91,53'  d,  'E'    e from dual union all
    select '10258931' a, '6'  b, '436,67'  c, '78,09'  d,  'E'    e from dual union all
    select '10258932' a, '7'  b, '784,88'  c, '23,19'  d,  'E'    e from dual union all
    select '10258932' a, '8'  b, '100,88'  c, '11,11'  d,  'E'    e from dual union all
    select '10258932' a, '9'  b, '300,88'  c, '22,22'  d,  'F'    e from dual union all
    select '10258932' a, '10' b, '468,25'  c, '78,33'  d,  'F'    e from dual
    )
    --
    -- end-of-test-data
    --
    select a, b, c, d, e,
           num_distinct_values
    from
    (
      select a, b, c, d, e,
             count(distinct e) over (partition by a) num_distinct_values
      from my_table)
    where num_distinct_values <= 1
    order by 1
    / 
    

    The county notes how the distinct non-null values in column e for each one.
    Where clause then selects those with count = 0 (this is where e = null) and count = 1.
    If the number is greater than 1, different values exist for this id.

    Choose what fits your condition ;-)

  • break the values of columns in separate lines

    Hello

    I have a query that returns the values of 4 columns of it. Of this, a column can have many values it contains separated by semocolon (-). The requirement now is if this particular column has more than one value, separated by the semocolon (-), then the query must return each of them separately as a new line and keep the rest, column values as common for each of these values of this colummn.

    For example, select...

    output:
    col1 col2 col3
    Risk of BB IE6 71 of the PACK_PWRMART file. DELETE_POSITION_WO_RISK ($FEEDINSTANCEID); PACK_PWRMART. DELETE_INSTRU_REL_POS_WO_RISK; QC 8401

    COL4
    2010-02-11 09:29:45 December 28, 2010

    Now, col3 has 3 values separated by (;). Therefore, the output of the query
    col1          col2                           col3( now split with 3 values)                                                          col4
    71     BB IE6 risk file     PACK_PWRMART.DELETE_POSITION_WO_RISK($FEEDINSTANCEID)        2/11/2010 9:29:45 AM 28-Dec-2010     
    72     BB IE6 risk file     PACK_PWRMART.DELETE_INSTRU_REL_POS_WO_RISK            2/11/2010 9:29:45 AM 28-Dec-2010     
    73             BB IE6 risk file             QC 8401                                                                                       2/11/2010 9:29:45 AM 28-Dec-2010
    The solution that I thought:

    I don't know if this can be achieved in a single SQL statement, so I thought I should write a block of code that will use the collection separate each of the value of this column and use some sort of record of object to insert the entire line in it 3 times (or the number of times as much as the values in this column) , but without success.

    Something like this:
    declare
    type feed_name is table of varchar2(4000);--feed_static.feed_description% type INDEX BY PLS_INTEGER;
    feed_nm feed_name;
    param_val feed_name;
    dat feed_name;
    feed_desc feed_name;
    str number;
    str1 varchar2(1000);
    begin
    select feed_description as "Feed Name" ,
           param_value as "Post_Proc Prarameter",
           '28-Dec-2010' as "COB date",
           ft.feed_type_description as "Feed Type"    
    BULK COLLECT INTO feed_nm,param_val,dat,feed_desc
    from feed_static fs, feed_parameter fp, feed_type ft 
    where fs.feed_id =fp.feed_id
    and fs.feed_type_id = ft.feed_type_id
    and fs.feed_type_id not in (4,15,16,25)
    and fp.param_name  = 'postproc'
    and fp.close_action_id is null
    and fs.feed_description in ('BB 0J0 risk file')--,'BB 1J1 risk file')
    order by  fs.feed_type_id,feed_description;
    FOR i IN 1..param_val.count
    loop
        select length((param_val(i))) - length(replace(param_val(i),';')) into str from dual;
               dbms_output.put_line(str); 
               for j in 1..str
                   loop
                        SELECT SUBSTR(param_val(i), 1 ,INSTR(param_val(i), ';', 1, j)-1) into str1 FROM dual;
                        dbms_output.put_line(str1); 
                        str1:=' ';
                   end loop;
    end loop;    
    end;
    But the "dbms_output.put_line (str1); does not give me o/p as required except the first value (assume thr are the 3 values of the column).
    Also I'm not sure of what I'm trying to do is in the right direction or not.

    I have not used any RECORDING still to poulate values separated again (I'm not sure about hoe to use)

    Cam anyone help me please with this code.

    Rgds,
    Aashish

    Try this:

    select feed_description as "Feed Name" ,
           param_value as "Post_Proc Prarameter",
           '28-Dec-2010' as "COB date",
           --ft.feed_type_description as "Feed Type" ,
           regexp_substr( ft.feed_type_description,'[^;]+',1,rown.seq)
    from feed_static fs, feed_parameter fp, feed_type ft, (SELECT LEVEL seq FROM DUAL
                        CONNECT BY LEVEL<=max(length(ft.feed_type_description)- length(replace(ft.feed_type_description,';'))))rown
    where fs.feed_id =fp.feed_id
    and fs.feed_type_id = ft.feed_type_id
    and fs.feed_type_id not in (4,15,16,25)
    and fp.param_name  = 'postproc'
    AND rown.seq<=(length(ft.feed_type_description)- length(replace(ft.feed_type_description,';')))
    and fp.close_action_id is null
    and fs.feed_description in ('BB 0J0 risk file')--,'BB 1J1 risk file')
    order by  fs.feed_type_id,feed_description;
    

    regexp_count started in 11g. It counts the number of models in a particular string. I replaced by length - length (repalce).
    You can replace the word 'max (length (ft.feed_type_description) - length (replace(ft.feed_type_description,';'))))' with 10 or 15, i.e. the maximum number of semicolons in the chain

  • How to remove duplicates in two separate lines in SQL?

    Hello

    I need to identify the data in double with two separate lines. See my below data structure.
    INDEX OF NAMES NAME_1 START_DATE END_DATE FLAG VALUE
    B ON 275 SE 13/12/2005-31/12/2010 1
    SELF 1 375
    SELF 1 475
    ON 275 SE 2 B 13/12/2005-31/12/2010
    SELF 2 375
    SELF 2 475
    ON SE 175 13/12/2006 AND 31/12/2010 B 3
    SELF 3 375
    SE ON 3 475

    This is my sample data. Here, the data is mirrored with different index columns. INDEX 1 and 2 contains the same combination group. I so need to identify one of the combination double (i.e. INDEX 1 or 2). Anyone can come up with the exact solution?

    Thank you

    I thought it had to do with the order of the INDEX field. The query checks only the value of the previous INDEX value.

    I think I found what the problem was.

    Try this:

    with test_table as
    (select 'SUR' NAME, 'SE' NAME_1, '275' VALUE, to_date('13/12/2005','DD/MM/YYYY') START_DATE, to_date('31/12/2010','DD/MM/YYYY') END_DATE, 'B' FLAG, 1 IND from dual union all
    select 'SUR', 'SE', '375', null, null, 'A', 1 from dual union all
    select 'SUR', 'SE', '475', null, null, 'A', 1 from dual union all
    select 'SUR', 'SE', '275', to_date('13/12/2005','DD/MM/YYYY') ,to_date('31/12/2010','DD/MM/YYYY') ,'B', 2 from dual union all
    select 'SUR', 'SE', '375', null, null, 'A', 2 from dual union all
    select 'SUR', 'SE', '475', null, null, 'A', 2 from dual union all
    select 'SUR', 'SE', '175', to_date('13/12/2006','DD/MM/YYYY'), to_date('31/12/2010','DD/MM/YYYY'), 'B', 3 from dual union all
    select 'SUR', 'SE', '375', null, null, 'A', 3 from dual union all
    select 'SUR', 'SE', '475', null, null, 'A', 3 from dual union all
    select 'SUR', 'SE', 'IPT', to_date('13/12/2005','DD/MM/YYYY'), to_date('31/12/2010','DD/MM/YYYY'), 'B', 100 from dual union all
    select 'SUR', 'SE', '375',null, null, 'A', 100 from dual union all
    select 'SUR', 'SE', 'AO', null, null, 'A', 100 from dual union all
    select 'SUR', 'SE', 'IPT', to_date('13/12/2005','DD/MM/YYYY'), to_date('31/12/2010','DD/MM/YYYY'), 'B', 218 from dual union all
    select 'SUR', 'SE', '375' ,null, null,'A' ,218 from dual union all
    select 'SUR', 'SE', 'AM' ,null, null,'A' ,218 from dual union all
    select 'SUR', 'SE', 'IPT' , to_date('13/12/2005','DD/MM/YYYY'), to_date('31/12/2008','DD/MM/YYYY'), 'B', 334 from dual union all
    select 'SUR', 'SE', '375' ,null, null,'A', 334 from dual union all
    select 'SUR', 'SE', 'AP',null, null, 'A', 334 from dual union all
    select 'SUR', 'SE', 'IPT' , to_date('01/01/2009','DD/MM/YYYY'), to_date('31/12/2010','DD/MM/YYYY'), 'B', 335 from dual union all
    select 'SUR', 'SE', '375' ,null, null,'A', 335 from dual union all
    select 'SUR', 'SE', 'AP',null, null, 'A', 335 from dual union all
    select 'SUR', 'SE', 'IPT' , to_date('13/12/2005','DD/MM/YYYY'), to_date('31/12/2010','DD/MM/YYYY'), 'B', 336 from dual union all
    select 'SUR', 'SE', '375' ,null, null,'A', 336 from dual union all
    select 'SUR', 'SE', 'AP',null, null, 'A', 336 from dual)
    SELECT name,
           name_1,
           value,
           start_date,
           end_date,
           flag,
           ind,
           MIN(diff_flag) over(PARTITION BY NAME, NAME_1, IND) min_flag
      FROM (SELECT t3.*,
                   CASE
                     WHEN lag(VALUE, lag_flag)OVER(ORDER BY IND, start_date, VALUE) != VALUE AND flag = 'A' THEN
                      1
                     WHEN (lag(value, lag_flag)OVER(ORDER BY IND, start_date, VALUE) != value
                        OR lag(start_date, lag_flag) OVER(ORDER BY IND, start_date, VALUE) != start_date
                        OR lag(end_date, lag_flag) OVER(ORDER BY IND, start_date, VALUE) != end_date)
                        AND flag = 'B' THEN
                      1
                     WHEN lag_flag = 0 THEN
                      1
                     ELSE
                      2
                     END diff_flag
              FROM (SELECT t2.*,
                           first_value(lag_count_flag) OVER(PARTITION BY NAME, NAME_1, IND
                                                                ORDER BY NAME, NAME_1, start_date) lag_flag
                      FROM (SELECT t1.*,
                                   CASE
                                     WHEN FLAG = 'B' THEN
                                      lag(COUNT, 1, 0)
                                      OVER(ORDER BY IND, start_date, VALUE)
                                   END lag_count_flag
                              FROM (SELECT t.*,
                                           COUNT(*) over(PARTITION BY NAME, NAME_1, IND) COUNT,
                                           row_number() over(PARTITION BY NAME, NAME_1, VALUE,
                                                                          START_DATE, END_DATE, FLAG
                                                                 ORDER BY IND) row_number
                                      FROM test_table t) t1) t2) t3) t4
     ORDER BY ind,
              start_date,
              VALUE;
    

    Published by: Manuel Vidigal on Abr 13, 2009 18:18

Maybe you are looking for

  • Satellite Pro A300 - after sleep mode the mouse no longer works

    Hi all Hope you can help me with this problem because I believe that I have tried everything I know and my next step is really formatting all the computer again and again without knowing if it will work this time, because that's what I just did, duri

  • How to create partition on HDD of the Satellite M50 130

    Can you tell me how to partition a unique two or three partitions HARD drive please?

  • Problems with sleeping mode

    One day in December, I got the vista updates and then something happened. After that, I was unable to use the sleep and hibernation mode because the computer will not wake up. Computer normally goes to sleep but doesn't wake up and start windows it s

  • File txt to ASCII binary (MATLAB equivalent?)

    Hello I just started using LabView two days ago and need help with which is probably very basic. My goal is to take a .txt file that contains some message (letters, numbers, etc.) and convert it to a stream series of bits. In MATLAB, I would do it li

  • EPrint iPhone5s for HP Officejet Pro 8000 Wireless

    After installation and a large number of failures, I still can't ePrint to work to my satisfaction. I thought that this ePrint would work as follows:iPhone has an image I want to print. Photo, email, web page. I click on the square with the arrow to