Need distinct rows with using distinct clause

I have following requirement
Empid startdate end organisation
1 1-jan-2008 O1
2 2-jan-2008 31-jul-08 O1
3 2-jan-2008 31-jul-08 O1
4 2-jan-2008 31-jul-08 O2
5 2-jan-2008 31-jul-08 O2
6 2-jan-2008 31-jul-08 O2
7 2-jan-2008 31-jul-08 O3
8 2-jan-2008 31-jul-08 O3
My requirement is to get a sql query that report me something like this
Empid startdate end organisation
1 1-jan-2008 O1
4 2-jan-2008 31-jul-08 O2
7 2-jan-2008 31-jul-08 O3
That is any empid, startdate, end for a given organization (ie organization should be distinct)
regards
vikas
Edited by: user634784 on Jan 19, 2009 4:05 AM

user634784 wrote:
But is there any way to get the same outcome without using the subquery.In reality... No.
You can hide the fact that you have to generate a row_number for the records by using a view... ;)
SQL> ed
Wrote file afiedt.buf
  1  create table t as select 1 as Empid, to_date('01-jan-2008','DD-MON-YYYY') as startdate, null as enddate, 'O1' as organisation from dual union all
  2                    select 2, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O1' from dual union all
  3                    select 3, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O1' from dual union all
  4                    select 4, to_date('5-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O2' from dual union all
  5                    select 5, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O2' from dual union all
  6                    select 6, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O2' from dual union all
  7                    select 7, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O3' from dual union all
  8*                   select 8, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O3' from dual
  9  /
Table created.
SQL> ed
Wrote file afiedt.buf
  1  create view vw_x as
  2* select empid, startdate, enddate, organisation, row_number() over (partition by organisation order by empid) rn from t
SQL> /
View created.
SQL> select * from vw_x where rn = 1;
     EMPID STARTDATE ENDDATE   OR         RN
         1 01-JAN-08           O1          1
         4 05-JAN-08 31-JUL-08 O2          1
         7 02-JAN-08 31-JUL-08 O3          1
SQL>

Similar Messages

  • Load distinct rows with sequence

    Hi All
    I have requirement at my client where we need to load distinct rows from the source TABLEA into TABLEB and add sequence in target TABLEB.
    As we know in Oracle we cant use sequence with distinct keyword, one of the solution is to use the sequence in target so ODI will capture
    distinct rows from source and use the sequence only in target table but if the source and target are on same schema then ODI doesn't create
    C$ table but it load data directly into target table and we get the error of invalid use of sequence.It wors fine if source and target table on different
    schema. I like to know if there is any way force ODI to create C$ table with distinct rows and load the sequence in target table only even source and
    target are on same schema. Otherwise I have create two interface to capture the distinct rows firct and then update the same table with sequence
    in second step. I really wanna avoid creating 2 interface for this simple job.Let me know if you have better solution.
    Thanks
    Kashif

    user634784 wrote:
    But is there any way to get the same outcome without using the subquery.In reality... No.
    You can hide the fact that you have to generate a row_number for the records by using a view... ;)
    SQL> ed
    Wrote file afiedt.buf
      1  create table t as select 1 as Empid, to_date('01-jan-2008','DD-MON-YYYY') as startdate, null as enddate, 'O1' as organisation from dual union all
      2                    select 2, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O1' from dual union all
      3                    select 3, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O1' from dual union all
      4                    select 4, to_date('5-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O2' from dual union all
      5                    select 5, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O2' from dual union all
      6                    select 6, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O2' from dual union all
      7                    select 7, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O3' from dual union all
      8*                   select 8, to_date('2-jan-2008','DD-MON-YYYY'), to_date('31-jul-08','DD-MON-YYYY'), 'O3' from dual
      9  /
    Table created.
    SQL> ed
    Wrote file afiedt.buf
      1  create view vw_x as
      2* select empid, startdate, enddate, organisation, row_number() over (partition by organisation order by empid) rn from t
    SQL> /
    View created.
    SQL> select * from vw_x where rn = 1;
         EMPID STARTDATE ENDDATE   OR         RN
             1 01-JAN-08           O1          1
             4 05-JAN-08 31-JUL-08 O2          1
             7 02-JAN-08 31-JUL-08 O3          1
    SQL>

  • Select distinct records without using distinct

    hi experts,
    my retrieved data like these:
    cnt_id cnt_type rcrd_id wrkflw_id
    558848     PRODUCT     553503     248     
    558848     PRODUCT     553503     248     
    558848     PRODUCT     553503     248     
    558808     PRODUCT     553463     248     
    558808     PRODUCT     553463     248     
    558808     PRODUCT     553463     248     
    558810     PRODUCT     553463     248     
    558810     PRODUCT     553463     248     
    558810     PRODUCT     553463     248
    now i want to select one record for each cnt_id without using any distinct function .. how can i do that?
    regards,
    SKP

    you can use the below query
    select * from t where rowid in (select max(rowid)
    from t group by cnt_id)You're query is not the equivalent of DISTINCT.
    SQL> ed
    Wrote file afiedt.buf
      1  create table t as
      2            (select 558848 as cnt_id, 'PRODUCT' as cnt_type, 553503 as rcrd_id, 248 as wrkflw_id from dual union all
      3             select 558848, 'RETURN', 553503, 248 from dual union all
      4             select 558848, 'PRODUCT', 553503, 248 from dual union all
      5             select 558808, 'PRODUCT', 553463, 248 from dual union all
      6             select 558808, 'PRODUCT', 553463, 248 from dual union all
      7             select 558808, 'PRODUCT', 553463, 248 from dual union all
      8             select 558810, 'PRODUCT', 553463, 248 from dual union all
      9             select 558810, 'PRODUCT', 553463, 248 from dual union all
    10*            select 558810, 'PRODUCT', 553463, 248 from dual)
    11  /
    Table created.
    Elapsed: 00:00:00.01
    SQL> select * from t where rowid in (select max(rowid) from t group by cnt_id);
        CNT_ID CNT_TYP    RCRD_ID  WRKFLW_ID
        558810 PRODUCT     553463        248
        558808 PRODUCT     553463        248
        558848 PRODUCT     553503        248
    Elapsed: 00:00:00.00
    SQL> select distinct * from t;
        CNT_ID CNT_TYP    RCRD_ID  WRKFLW_ID
        558810 PRODUCT     553463        248
        558808 PRODUCT     553463        248
        558848 RETURN      553503        248
        558848 PRODUCT     553503        248
    Elapsed: 00:00:00.00
    SQL>

  • Query to get row with max values for distinct

    I have a table test with ID, ADID, MTMST columns.
    ID     ----ADID----     MTMST
    1     ----100----     24-MAR-12 08.17.09.000000 PM
    1     ----101----     24-MAR-12 08.18.15.000000 PM
    1     ----102----     24-MAR-12 08.18.56.000000 PM
    2     ----103----     24-MAR-12 08.19.21.000000 PM
    2     ----104----     24-MAR-12 08.19.36.000000 PM
    2     ----105----     24-MAR-12 08.19.46.000000 PM
    3     ----99----      22-MAR-12 09.48.22.000000 PM
    I need the rows with max ADID for each ID.
    I used the following query but it provided max ADID of the table but not the distinct ID
    select * from test where ADID in (select max(ADID) from test where id in (select distinct(id) from test where mtmst > sysdate -1))
    Result:*
    ID     ----ADID----     MTMST
    2     ----105----     24-MAR-12 08.19.46.000000 PM
    Expected result:*
    ID     ----ADID----     MTMST
    1     ----102----     24-MAR-12 08.18.56.000000 PM
    2     ----105----     24-MAR-12 08.19.46.000000 PM
    Thanks,
    Dheepan
    Edited by: Dheepan on Mar 24, 2012 9:53 AM

    select id, adid, mtmst from test where (id, adid) in (select id, max(adid) from test group by id) and MTMST>sysdate-1
    is the answer.

  • Using distinct with an Order by

    Hi all,
    I'm not an expert SQL coder and I've got stuck with the following issue.
    I have a table named Workorder which contains a set of orders. Orders with status_id = 2 contain an error and this need to be re-submitted:
    [ ID ] [WO_ID] [STATUS_ID]
    1 10 2
    2 10 1
    3 20 2
    So apparentely it seems very simple, however when orders are re-submitted things get complicated.
    In the above query I need to pickup -just- the following row:
    [ ID ] [WO_ID] [STATUS_ID]
    3 20 2
    The following row needs to be excluded from the list:
    [ ID ] [WO_ID] [STATUS_ID]
    1 10 2
    Because the WO_ID has been later re-submitted successufully:
    [ ID ] [WO_ID] [STATUS_ID]
    2 10 1
    So I need to pickup all workorders with a distinct on WO_ID ordered by ID desc, so that the distinct row contains just the highest ID (the latest order re-submitted).
    I've tried in several ways, however I wasn't able to mix distinct + order by.
    Maybe it can be done also in some other simpler ways ?
    Thanks a lot
    Frank

    So, if the last ID for each WO_ID has STATUS_ID=2, that row needs to in the output.
    But if the last ID has a different STATUS_ID, then that WO_ID is not to be in the output at all?
    Perhaps this could work for you:
    select
    max(id) as id,
    wo_id,
    max(status_id) keep (dense_rank last order by id) as status_id
    from workorder
    group by wo_id
    having max(status_id) keep (dense_rank last order by id) = 2
    order by wo_idEdit:
    Or an alternative using analytic functions:
    select
    id,
    wo_id,
    status_id
    from (
       select
       id,
       wo_id,
       status_id,
       last_value(status_id) over (
          partition by wo_id
          order by id
          rows between unbounded preceding and unbounded following
       ) as last_status
       from workorder
    where last_status = 2If your workorder table actually contains several other columns you wish to select along with the id and status, then the analytic way can be much easier than a bunch of "keep" expressions ;-)
    Edited by: Kim Berg Hansen on Nov 29, 2011 12:22 PM

  • SSRS reporting with sharepoint list using Distinct and Multivalue parameters

    i want create ssrs report with sharepoint list using ms-vs(2008). i want create Distinct multivalue parameters by using CAML query. There is any way we put CAML query where we use Distinct keyword and IN clause in CAML query... i hope all experts will
    understand my poor English... sorry for poor English.. plz help me

    Hi AsifMehmood,
    Per my understanding you have create an SSRS report with SharePoint list, now you don’t know to create the distinct parameters by using CAML query,  right?
    For the CAML language doesn’t have any reserved word (or tag) to set this particular filter to remove duplicate results, but we can use the custom code to do this function. I have tested on my local environment and we can do that by create one hidden parameter(Param1)
    to get all the values from the fields which will  add the filter and then create another parameter(Param2) to get the distinct values based on the Param1, we use the custom code to do the deduplication.
    Step by Steps information in below thread for your reference to create the parameters and the custom code:
    "How to get distinct values of sharepoint column using SSRS"
    Other similar thread for your reference:
    https://audministrator.wordpress.com/2014/02/17/sharepoint-list-add-distinct-parameter-value/
    If your problem still exists, please feel free to ask and also try to provide us more details information.
    Regards
    Vicky Liu

  • Query to find no of peoples with the same age(using distinct)

    query to find no of peoples with the same age(using distinct)
    Edited by: swordfish3 on Mar 7, 2009 9:24 PM

    it would be helpful if you posted some proper sample data with proper expected results.
    The easier you make it for us to help you, the more likely you will get helped.

  • Using ROWID returns less rows than if use distinct in query

    Hi,
    I am writting  the following query to get distinct purchase order number from a specific received date. this returns me total 620 rows.:
    select  distinct pha.segment1 from apps.po_headers_all pha, apps.RCV_TRANSACTIONS rcv
    where 1=1
    and trunc(rcv.transaction_date) between to_date(:P_FROM_DATE,'YYYY/MM/DD HH24:MI:SS') and to_date(:P_TO_DATE,'YYYY/MM/DD HH24:MI:SS')
    and pha.po_header_id=rcv.po_header_id
    and pha.type_lookup_code='STANDARD'
    and pha.authorization_status ='APPROVED'
    and pha.cancel_flag='N'
    if i write the query using ROWID to get the distinct Purchase order number its giving me 580 rows:
    select  pha.segment1 from apps.po_headers_all pha, apps.RCV_TRANSACTIONS rcv
    where 1=1
    and trunc(rcv.transaction_date) between to_date(:P_FROM_DATE,'YYYY/MM/DD HH24:MI:SS') and to_date(:P_TO_DATE,'YYYY/MM/DD HH24:MI:SS')
    and pha.po_header_id=rcv.po_header_id
    and rcv.rowid=(select max(rowid) from apps.RCV_TRANSACTIONS rcv where rcv.po_header_id=pha.po_header_id)
    and pha.type_lookup_code='STANDARD'
    and pha.authorization_status ='APPROVED'
    and pha.cancel_flag='N';
    Can anyone tell me why? I want to use this ROWID query in a valueset in oracle apps.

    That's probably because some purchase orders have rcv transactions out of the range (p_from_date, p_to_date). You should include the condition on the dates in the (select max(rowid)...) subquery as well. And more generally, the first query seems like a better/simpler choice than the second one.
    Hope it helps.

  • Display distinct rows from Oracle table without using "DISTINCT" keyword.

    How to retrieve distinct rows from oracle table without using 'DISTINCT' keyword in SQL?
    Thanks in advance.
    Mihir

    Welcome to the forum.
    Besides GROUP BY you can use UNIQUE instead of DISTINCT as well, but that's probably not wanted here ;) , and the ROW_NUMBER() analytic:
    SQL> create table t as
      2  select 1 col1 from dual union all
      3  select 1 from dual union all
      4  select 2 from dual union all
      5  select 3 from dual union all
      6  select 4 from dual union all
      7  select 4 from dual;
    Table created
    SQL> select col1 from t;
          COL1
             1
             1
             2
             3
             4
             4
    6 rows selected
    SQL> select distinct col1 from t;
          COL1
             1
             2
             3
             4
    SQL> select unique col1 from t;
          COL1
             1
             2
             3
             4
    SQL> select col1 from t group by col1;
          COL1
             1
             2
             3
             4
    SQL> select col1
      2  from ( select col1
      3         ,      row_number() over (partition by col1 order by col1) rn
      4         from   t
      5       )
      6  where rn=1;
          COL1
             1
             2
             3
             4

  • Using distinct and orderby in the select statment

    Hi All,
    Can anyone tell me what is the purpose of using distinct and orderby in the select statment.

    Hi,
    Using the distinct function with more than one column yields some substantial results. SQL will return the rows with distinct or unique combinations of those columns. Assume this same employee table has another column including the salary of each employee. With the use of the distinct function we can pull a list of unique job titles - salaries.
    SQL Code:
    SELECT DISTINCT job_titles, salary FROM employees;
    SQL has returned all the rows with unique combinations of job titles and salaries. Any duplicate combinations of job titles and salaries will be ignored. For example if we had two CEOs in the table making the same salary each year, only one row would be returned but if we had two CEOs with different salaries, both rows would be returned.
    Order by
    The SQL ORDER BY clause comes in handy when you want to sort your SQL result sets by some column(s). For example if you want to select all the persons from the already familiar Customers table and order the result by date of birth, you will use the following statement:
    SELECT * FROM Customers
    ORDER BY DOB
    As you can see the rows are sorted in ascending order by the DOB column, but what if you want to sort them in descending order? To do that you will have to add the DESC SQL keyword after your SQL ORDER BY clause:
    SELECT * FROM Customers
    ORDER BY DOB DESC
    If you don't specify how to order your rows, alphabetically or reverse, than the result set is ordered alphabetically, hence the following to SQL expressions produce the same result:
    SELECT * FROM Customers
    ORDER BY DOB
    SELECT * FROM Customers
    ORDER BY DOB ASC
    You can sort your result set by more than one column by specifying those columns in the SQL ORDER BY list. The following SQL expression will order by DOB and LastName:
    SELECT * FROM Customers
    ORDER BY DOB, LastName
    if its useful reward points

  • Query with 2 level of breaks overlapings, one with a distinct constraint

    My boss asked me, for an Apex graph, to give for one day
    every 10 min the number of UNIQUE people (id) connected in the last 30 minutes.
    It is because this Unique ID count that I cannot solve this, but I am convinced it can be done using analytical or model clause.
    The folllwiing test case perfectly emulate the set of data as they comes from Websphere logs:
    --  We want :
    --    One row every 10 minutes that gives the count of UNIQUE  ID
    --        connected in the last 30 min before this point
    -- in this test case we assume that at 08h00 one user connects
    --     every second during one hour.
    with v as (
      select trunc(dbms_random.value(1,2000)+1) id,
           trunc(sysdate) + 80/24 + level/86400 sec from           <- this is  a typo, I wanted 8/24
      dual connect by level < 3600
    select id, to_char(sec,'YYYY-MM-DD HH24:MI:SS') from v
          ID   Time
           568 2011-07-23 08:48:19
          1057 2011-07-23 08:48:20
          1864 2011-07-23 08:48:21
          1500 2011-07-23 08:48:22
           917 2011-07-23 08:48:23
          1844 2011-07-23 08:48:24
           779 2011-07-23 08:48:25
           448 2011-07-23 08:48:26
           382 2011-07-23 08:48:27
           256 2011-07-23 08:48:28
          1821 2011-07-23 08:48:29
           872 2011-07-23 08:48:30
           658 2011-07-23 08:48:31
    .Edited by: bpolarski on 20 juil. 2011 12:10 added typo comment

    Hi Solomon
    I don't think the numbers are correct. There are 1200 rows before 8:20, but your query is showing 1569 distinct sessions.
    with v as (
               select  --+materialize
                        trunc(dbms_random.value(1,2000)+1) id,
                       trunc(sysdate) + 80/24 + level/86400 sec
                 from  dual connect by level < 3600
    select
        count(*),
        count(distinct id)
    FROM
        v where sec <= TO_DATE('23/07/2011 08:20:00','dd/mm/yyyy hh24:mi:ss')
    SQL> with v as (
      2             select  --+materialize
      3                      trunc(dbms_random.value(1,2000)+1) id,
      4                     trunc(sysdate) + 80/24 + level/86400 sec
      5               from  dual connect by level < 3600
      6            )
      7  select
      8      count(*),
      9      count(distinct id)
    10  FROM
    11      v where sec <= TO_DATE('23/07/2011 08:20:00','dd/mm/yyyy hh24:mi:ss')
    12  /
      COUNT(*) COUNT(DISTINCTID)
          1200               910I know this might not be the neatest way to get the result, but I think this is the correct one. I tried with analytics but I kept hitting problems with the ranges...
    with v as (
               select  trunc(dbms_random.value(1,2000)+1) id,
                       trunc(sysdate) + 80/24 + level/86400 sec
                 from  dual connect by level < 3600
    SELECT
        sec_10_min,
        (   SELECT
                count(distinct l.id)
            FROM
                v l
            WHERE
                l.sec >= sec_10_min - NUMTODSINTERVAL(30,'MINUTE')
            AND
                l.sec <= sec_10_min
         ) ct
    FROM
        (   SELECT
                sec_10_min
            FROM
                    select  trunc(sec,'HH') + trunc(to_char(sec,'MI') / 10) / 144 sec_10_min
                    from  v
                    WHERE
                        rownum > 0
            group by
                sec_10_min
      order by sec_10_min
    SQL> with v as (
      2             select  trunc(dbms_random.value(1,2000)+1) id,
      3                     trunc(sysdate) + 80/24 + level/86400 sec
      4               from  dual connect by level < 3600
      5            )
      6  SELECT
      7      sec_10_min,
      8      (   SELECT
      9              count(distinct l.id)
    10          FROM
    11              v l
    12          WHERE
    13              l.sec >= sec_10_min - NUMTODSINTERVAL(30,'MINUTE')
    14          AND
    15              l.sec <= sec_10_min
    16       ) ct
    17  FROM
    18      (   SELECT
    19              sec_10_min
    20          FROM
    21              (
    22                  select  trunc(sec,'HH') + trunc(to_char(sec,'MI') / 10) / 144 sec_10_min
    23                  from  v
    24                  WHERE
    25                      rownum > 0
    26              )
    27          group by
    28              sec_10_min
    29      )
    30    order by sec_10_min
    31  /
    SEC_10_MIN                  CT
    23/07/2011 08:00:00          0
    23/07/2011 08:10:00        511
    23/07/2011 08:20:00        897
    23/07/2011 08:30:00       1176
    23/07/2011 08:40:00       1179
    23/07/2011 08:50:00       1188HTH
    David
    Edited by: Bravid on Jul 20, 2011 2:43 PM
    Edited by: Bravid on Jul 20, 2011 2:48 PM
    Updated NLS to show times in the output

  • Using distinct and sequences

    I have a problem that I'm sure has a simple solution.
    I'm trying to insert unique records into one table from another table that has duplicates. However, I cant use the sequence for my primary key with the distinct operator. eg.:
    INSERT INTO unique_table (pkey,fkey,name)
    SELECT DISTINCT seq.nextval, col1, col2
    FROM dup_table;
    it is the combination of fields col1 and col2 that must be unique. Please help.

    correct, the distinct clause returns unique rows. you could
    create a trigger for your table then just insert your dup_tab
    into the uniq_tab
    insert into uniq_tab (select distinct col1,col2 from dup_tab);
    with the trigger, your dup_tab will be populated with uniq
    rows on col1,col2
    Hope this helps
    Jay

  • How to delete the duplicate data in between two distinct rows in SQL?

    Hi,
    I need to identify the duplicate data with two distinct rows. See my data structure below.
    NAME NAME_1 VALUE START_DATE END_DATE FLAG INDEX
    SUR SE 275 13/12/2005 31/12/2010 B 1
    SUR SE 375 A 1
    SUR SE 475 A 1
    SUR SE 275 13/12/2005 31/12/2010 B 2
    SUR SE 375 A 2
    SUR SE 475 A 2
    SUR SE 175 13/12/2006 31/12/2010 B 3
    SUR SE 375 A 3
    SUR SE 475 A 3
    This is my sample data. Here data are duplicate with different index columns. INDEX 1 and 2 contains same group of combination. So i need to identify any one of duplicate combination(i.e INDEX 1 or 2). Can anyone come up with exact solution?
    Thanks

    Try this:
    with test_table as
    (select 'SUR' NAME, 'SE' NAME_1, 275 VALUE, '13/12/2005' START_DATE, '31/12/2010' 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, '13/12/2005' ,'31/12/2010' ,'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, '13/12/2006', '31/12/2010', '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 )
    select t.*,
           CASE WHEN START_DATE IS NULL THEN
             first_value(row_number) OVER (PARTITION BY NAME, NAME_1, IND ORDER BY START_DATE)
           ELSE
             row_number
           END row_number
    from (
    SELECT t.*,
           CASE WHEN START_DATE IS NOT NULL THEN
             row_number() over(PARTITION BY NAME, NAME_1,VALUE, START_DATE, END_DATE, FLAG
                               ORDER BY IND)
           END row_number
      FROM test_table t) t
    order by IND, start_dateNote that this is only checking for diferences in the rows where start_date is not null. Do you want to also check if the records where start_date is null it there are differences? If so you can do this:
    with test_table as
    (select 'SUR' NAME, 'SE' NAME_1, 275 VALUE, '13/12/2005' START_DATE, '31/12/2010' 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, '13/12/2005' ,'31/12/2010' ,'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, '13/12/2006', '31/12/2010', '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 )
    SELECT t.*,
           MIN(row_number) OVER(PARTITION BY NAME, NAME_1, IND) MIN
      FROM (SELECT t.*,
                   row_number() over(PARTITION BY NAME, NAME_1, VALUE,
                                                  START_DATE, END_DATE, FLAG
                                         ORDER BY IND) row_number
              FROM test_table t) t
    ORDER BY IND,
              start_date;Edited by: Manuel Vidigal on 13/Abr/2009 12:05

  • How to create an expression using distinct()?

    I want to create an expression for the following SQL statement:
    select distinct aCol from mytable where bCol = 123 and cCol = 'something';
    My expression without using the distinct() is followed:
    Expression exp = new ExpressionBuilder().get("bcol").
    equal(123).and(new ExpressionBuilder().
    get("cCol").equal("something"));
    ReportQuery query = new ReportQuery(mytable.class, exp);
    query.addAttribute("aCol");
    Vector queryResult = (Vector)toplinkSession.executeQuery(query);
    Where can I place the "distinct()" in this expression. I tried several ways, but TopLink always created the SQL statement with the 'distinct()' in the wrong place. I noted someone also had this problem and I tried the solution posted by Doug Clarke, but still did not work for me.
    thanks

    Hi,
    You need to call useDistinct() on the query to generate the needed sql.
    By the way, you need to use the same ExpressionBuilder instance to build a query object (i.e. not use New multiple times).
    King

  • Creating Materialized View with the Distinct key word

    Hi
    I need help to create Materialized View with the Distinct key word.
    my query is
    select distinct col1, col2 from t1;
    is there any alternate of DISTINCT because I can not refresh the MV as fast on demand if I am using it and Fast on Demand is a must for me.

    hi
    check out this link
    http://download-west.oracle.com/docs/cd/B12037_01/server.101/b10736/basicmv.htm#i1007299
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/intro.htm#sthref183
    hope this helps
    CHeers

Maybe you are looking for

  • Creating an XML document from a DTD in Java

    Hi All, I need help on the following requirement very badly. Pls help me. I have a requirement to implement with java and XML. I am quit new to XML.Can any of you pls help me. I have a DTD file. I need to generate XML document from it using java code

  • Getting an error trying to install Crystal Reports 2008 on a 64 bit Windows

    reformatted my computer and now I'm trying to install Crystal Reports 2008 on 64 bit windows 7 box.  When the "Registering modules" portion of the install comes up, I get a message that a dll has failed to register.  I saw something about not having

  • External iSight makes noises after connecting

    After connecting my external iSight to my ibook g4, the camera makes a strange noise, probably coming out of its mic or the lens which is like trying to focus..or I don´t know. It´s a short buzzing sound which sometimes appears while the camera opera

  • Which is better? iPad Smart Cover. Polyurethane or Leather?

    Same

  • Logo at the start screen

    Hello everyone, I could already delete the ripple animation which appears as you want to login into SAP B1, however is it also possible to delete the photo of the nice smiling person at the login screen? I was told that it could be deleted in the bac