Selecting unique records- Removing consecutive same data

HI,
am having a table where in some x,y,msg_date_info fields are there...here the data is in huge number...i need to fetch the data from this table subject to the following query conditions.
SELECT  X longit,Y latit,MSG_DATE_INFO,row_number() over (order by MSG_DATE_INFO asc) SlNo FROM
(SELECT distinct x,y,MSG_DATE_INFO,row_number() over (order by MSG_DATE_INFO desc) r
  FROM TRACKING_REPORT WHERE MSISDN='123456789') WHERE R between 1 and 20this works fine...
here one more thing i want to add up...this query results in 20 rows as expected and i want to filter the records if consecutive x and y values of these rows are same and give only unique values of x and y(condition that same x and y can be there somewhere in the order of data).
this example will show what is my requirement in detail....and this is the output of the above query
>
80.20550609     13.09469998     08-Mar-10 19:23:23     1
80.20550609     13.09469998     08-Mar-10 19:28:37     2
80.20087123     13.09437811     08-Mar-10 19:33:25     3
80.20550609     13.09469998     08-Mar-10 19:38:24     4
80.20550609     13.09469998     08-Mar-10 19:43:25     5
80.20550609     13.09469998     08-Mar-10 19:48:25     6
80.20087123     13.09437811     08-Mar-10 19:53:25     7
80.20087123     13.09437811     08-Mar-10 19:58:24     8
80.20550609     13.09469998     08-Mar-10 20:03:25     9
80.20087123     13.09437811     08-Mar-10 20:08:24     10
80.20550609     13.09469998     08-Mar-10 20:13:24     11
80.20087123     13.09437811     08-Mar-10 20:18:37     12
80.20550609     13.09469998     08-Mar-10 20:23:32     13
80.20550609     13.09469998     08-Mar-10 20:28:25     14
80.20550609     13.09469998     08-Mar-10 20:33:23     15
80.20550609     13.09469998     08-Mar-10 20:38:24     16
80.20550609     13.09469998     08-Mar-10 20:43:24     17
80.20550609     13.09469998     08-Mar-10 20:48:24     18
80.20550609     13.09469998     08-Mar-10 20:53:22     19
80.20550609     13.09469998     08-Mar-10 20:58:24     20
>
from this output i need to filter out CONSECUTIVE unique x and y values. and the output has to be like
>
80.20550609     13.09469998     08-03-10 19:23     1
80.20087123     13.09437811     08-03-10 19:33     3
80.20550609     13.09469998     08-03-10 19:48     6
80.20087123     13.09437811     08-03-10 19:53     7
80.20550609     13.09469998     08-03-10 20:03     9
80.20087123     13.09437811     08-03-10 20:08     10
80.20550609     13.09469998     08-03-10 20:13     11
80.20087123     13.09437811     08-03-10 20:18     12
80.20550609     13.09469998     08-03-10 20:58     20
>
how to go about this requirement?
Edited by: Aemunathan on Mar 9, 2010 5:45 PM

The following gives the same results on your test data but maybe it's more accurate because searches both for changes in x and in y:
SQL> with mytab as (
  2  select 80.20550609 x, 13.09469998 y, '08-Mar-10 19:23:23' mydate, 1 rn from dual union
  3  select 80.20550609,13.09469998, '08-Mar-10 19:28:37', 2 from dual union
  4  select 80.20087123,13.09437811, '08-Mar-10 19:33:25', 3 from dual union
  5  select 80.20550609,13.09469998, '08-Mar-10 19:38:24', 4 from dual union
  6  select 80.20550609,13.09469998, '08-Mar-10 19:43:25', 5 from dual union
  7  select 80.20550609, 13.09469998, '08-Mar-10 19:48:25', 6 from dual union
  8  select 80.20087123, 13.09437811, '08-Mar-10 19:53:25', 7 from dual union
  9  select 80.20087123, 13.09437811, '08-Mar-10 19:58:24', 8 from dual union
10  select 80.20550609, 13.09469998, '08-Mar-10 20:03:25', 9 from dual union
11  select 80.20087123, 13.09437811, '08-Mar-10 20:08:24', 10 from dual union
12  select 80.20550609,13.09469998, '08-Mar-10 20:13:24', 11 from dual union
13  select 80.20087123, 13.09437811, '08-Mar-10 20:18:37', 12 from dual union
14  select 80.20550609, 13.09469998, '08-Mar-10 20:23:32', 13 from dual union
15  select 80.20550609, 13.09469998, '08-Mar-10 20:28:25', 14 from dual union
16  select 80.20550609, 13.09469998, '08-Mar-10 20:33:23', 15 from dual union
17  select 80.20550609, 13.09469998, '08-Mar-10 20:38:24', 16 from dual union
18  select 80.20550609, 13.09469998, '08-Mar-10 20:43:24', 17 from dual union
19  select 80.20550609, 13.09469998, '08-Mar-10 20:48:24', 18 from dual union
20  select 80.20550609, 13.09469998, '08-Mar-10 20:53:22', 19 from dual union
21  select 80.20550609, 13.09469998, '08-Mar-10 20:58:24', 20 from dual
22  )
23  select x, y, mydate, rn from (
24  select x, y, mydate, rn, nvl(lead(x) over (order by rn),0) next_x
25         , nvl(lead(y) over (order by rn),0) next_y
26  from mytab
27  ) where next_x != x or next_y != y;
                   X                    Y MYDATE                               RN
         80.20550609          13.09469998 08-Mar-10 19:28:37                    2
         80.20087123          13.09437811 08-Mar-10 19:33:25                    3
         80.20550609          13.09469998 08-Mar-10 19:48:25                    6
         80.20087123          13.09437811 08-Mar-10 19:58:24                    8
         80.20550609          13.09469998 08-Mar-10 20:03:25                    9
         80.20087123          13.09437811 08-Mar-10 20:08:24                   10
         80.20550609          13.09469998 08-Mar-10 20:13:24                   11
         80.20087123          13.09437811 08-Mar-10 20:18:37                   12
         80.20550609          13.09469998 08-Mar-10 20:58:24                   20
9 rows selected.Max
http://oracleitalia.wordpress.com

Similar Messages

  • Selection of records based on minimum date actioned

    Post Author: jrdoyle
    CA Forum: Data Connectivity and SQL
    Hi!
    I've been building a report that displays records, grouped by the Service Department  to which they have been assigned; however I need to constrain the report to only show the Service Department to which the record was first assigned.  I had tried to group the report by incident reference #, and had in the details the actions taken agains the record, the date of the action, the SVD to which it was assigned, etc.  In the Select Expert, I have the following:
    {INC_DATA.EVENT_TYPE} = "i" and{SERV_DEPT.SERV_DEPT_SC} = "DISPATCH" and{INCIDENT.DATE_LOGGED} in DateTime (2007, 05, 01, 00, 00, 00) to DateTime (2007, 05, 30, 00, 00, 00) and{SERV_DEPT_1.SERV_DEPT_SC} in ["CUSTHOME", "CUSTWEST", "HARDWARE"]
    The SERV_DEPT_1 table will displays the information about the Service Department to which the records are assigned.  I need to be able to count only the minimum date of assignment.  I've tried using the Minimum function, but it appears that I then can't summarize (count records) higher up in the report groups, as it gets evaluated after (?) the groups are made.
    Is anyone able to offer suggestions as to how I might go about this?  I have tried to somehow flag records in the details which meet the criteria, but haven't been able to come up with anything yet.
    Thanks!

    Post Author: Jagan
    CA Forum: Data Connectivity and SQL
    I'm not quite sure how/where you tried to use the Minimum function - sounds like you used it in the record selection formula? Anyway, if you want the report to have only the earliest record per service department group then you can use the group selection expert, e.g.{incident.date_logged} = minimum({incident.date_logged}, {serv_dept_1.serv_dept_sc})If you want to display the earliest record but still have the other records there for processing then sort on {incident.date_logged} ascending, suppress the details, and print in the {serv_dept_1.serv_dept_sc} group header. i.e the record you're "looking" at in the group header is the first one for the group.The difference between the two is that the former will only have one record per service department group (assuming the date_logged is unique per incident per department) while the latter will have all records but only display one. This makes a difference when using the built-in summary functions.

  • Sql query - Selecting last recorded values for each date in specified period

    Hello,
    Can someone please help me with my problem.
    I'm trying to get last recorded balance for each day for specific box (1 or 2) in specified period of days from ms access database using ADOTool.
    I'm trying to get that information with SQL query but so far unsuccessfully...  
    My table looks like this:
    Table name: TestTable
    Date Time Location Box Balance
    20.10.2014. 06:00:00 1 1 345
    20.10.2014. 12:00:00 1 1 7356
    20.10.2014. 18:45:00 1 1 5678
    20.10.2014. 23:54:00 1 1 9845
    20.10.2014. 06:00:02 1 2 35
    20.10.2014. 12:00:04 1 2 756
    20.10.2014. 18:45:06 1 2 578
    20.10.2014. 23:54:10 1 2 845
    21.10.2014. 06:00:00 1 1 34
    21.10.2014. 12:05:03 1 1 5789
    21.10.2014. 15:00:34 1 1 1237
    21.10.2014. 06:00:00 1 2 374
    21.10.2014. 12:05:03 1 2 54789
    21.10.2014. 15:00:34 1 2 13237
    22.10.2014. 06:00:00 1 1 8562
    22.10.2014. 10:00:00 1 1 1234
    22.10.2014. 17:03:45 1 1 3415
    22.10.2014. 22:00:00 1 1 6742
    22.10.2014. 06:00:05 1 2 562
    22.10.2014. 10:00:16 1 2 123
    22.10.2014. 17:03:50 1 2 415
    22.10.2014. 22:00:10 1 2 642
    23.10.2014. 06:00:00 1 1 9876
    23.10.2014. 09:13:00 1 1 223
    23.10.2014. 13:50:17 1 1 7768
    23.10.2014. 19:47:40 1 1 3456
    23.10.2014. 21:30:00 1 1 789
    23.10.2014. 23:57:12 1 1 25
    23.10.2014. 06:00:07 1 2 976
    23.10.2014. 09:13:45 1 2 223
    23.10.2014. 13:50:40 1 2 78
    23.10.2014. 19:47:55 1 2 346
    23.10.2014. 21:30:03 1 2 89
    23.10.2014. 23:57:18 1 2 25
    24.10.2014. 06:00:55 1 1 346
    24.10.2014. 12:30:22 1 1 8329
    24.10.2014. 23:50:19 1 1 2225
    24.10.2014. 06:01:00 1 2 3546
    24.10.2014. 12:30:26 1 2 89
    24.10.2014. 23:51:10 1 2 25
    Let's say the period is 21.10.2014. - 23.10.2014. and I want to get last recorded balance for box 1. for each day. The result should look like this:
    Date Time Location Box Balance
    21.10.2014. 15:00:34 1 1 1237
    22.10.2014. 22:00:00 1 1 6742
    23.10.2014. 23:57:12 1 1 25
    So far I've managed to write a query that gives me balance for ONLY ONE date (date with highest time in whole table), but I need balance for EVERY date in specific period.
    My incorrect code (didn't manage to implement "BETWEEN" for dates...):
    SELECT TestTable.[Date], TestTable.[Time], TestTable.[Location], TestTable.[Box], TestTable.[Balance]
    FROM TestTable
    WHERE Time=(SELECT MAX(Time)
    FROM TestTable
    WHERE Location=1 AND Box=1 );
    Tnx!
    Solved!
    Go to Solution.

    For loop
    following query keep day (here 24 in below query) Variable from ( 1 to 28-29/30/31 as per month)
    SELECT TOP 1 TestTable.[Date], TestTable.[Time], TestTable.[Location], TestTable.[Box], TestTable.[Balance]
    FROM Test Table.
    WHERE  Time=(SELECT MAX(Time) FROM TestTable WHERE Location=1 AND Box=1 )
    AND DATE = "2014-10-24";
    PBP (CLAD)
    Labview 6.1 - 2014
    KUDOS ARE WELCOMED.
    If your problem get solved then mark as solution.

  • Choosing unique record based on latest date

    I have a column, say Name, in which a person's name appears with multiple transactions. Each transaction has an unique date. I want to return just the latest transaction by date for each person.
    If I write my select as:
    select Name, Trans_Dt from <Table>;
    I of course get a list of all transactions listing person and date.
    I've tried this:
    select Name, Trans_Dt from <Table>
    group by Trans_Dt having greatest(Trans_Dt).
    This doesn't work. Any suggestions?

    select name, trans_dt
    from
       select
          Name,
          Trans_Dt,
          max(Trans_Dt) over(partition by name) as max_trans_date
       from <Table>
    where Trans_Dt= max_Trans_trans_date;Would be one way.

  • Unique records

    I've created a dynamic table that retrieves multiple records
    for an individual. I've included a submit button in each line
    created with the unique record ID as hidden data to be sent for
    selecting a update page, but the data I get is all of the unique
    records ID's, like 45,46,48,49,50 where I only wanted #46. The
    example in the workbook shows an href call to select a particular
    record. Is it possible to use either a submit key or a radio button
    to select a certain record to update? I have additional data I need
    to pass along to the next page so an href pointer won't really
    work. What am I doing wrong?

    If you don't want to use an HREF pointer, then you will need
    to use some JavaScript to let you know which record the user has
    selected. Instead of using a type="submit", use a type="button" and
    then include the following onClick statement in the tag:
    onClick="document.form1.selectID=#rs_AP_Cert_Quest.Key#;
    document.form1.submit();"
    Then include a hidden form element named selectID at the
    bottom of the page.
    I probably would use a function instead of coding it directly
    in case I needed to add some more functionality and it would get to
    messy to do all of the JS inline. But the above code will get you
    running.

  • One-to-many selfjoin removing records with the same ranking or with a substitute

    Sorry for my bad choice of discussion title, feel free to suggest me a more pertinent one
    I've rewritten post for clarity and following the FAQ.
    DB Version
    I'm using Oracle Enterprise 10g 10.2.0.1.0 64bit
    Tables involved
    CREATE TABLE wrhwr (
    wr_id INTEGER PRIMARY KEY,
    eq_id VARCHAR2(50) NULL,
    date_completed DATE NULL,
    status VARCHAR2(20) NOT NULL,
    pmp_id VARCHAR2(20) NOT NULL,
    description VARCHAR2(20) NULL);
    Sample data
    INSERT into wrhwr  VALUES (1,'MI-EXT-0001',date'2013-07-16','Com','VER-EXC','Revisione')
    INSERT into wrhwr VALUES  (2,'MI-EXT-0001',date'2013-07-01','Com','VER-EXC','Verifica')
    INSERT into wrhwr  VALUES (3,'MI-EXT-0001',date'2013-06-15','Com','VER-EXC','Revisione')
    INSERT into wrhwr  VALUES (4,'MI-EXT-0001',date'2013-06-25','Com','VER-EXC','Verifica')
    INSERT into wrhwr  VALUES (5,'MI-EXT-0001',date'2013-04-14','Com','VER-EXC','Revisione')
    INSERT into wrhwr  VALUES (6,'MI-EXT-0001',date'2013-04-30','Com','VER-EXC','Verifica')
    INSERT into wrhwr  VALUES (7,'MI-EXT-0001',date'2013-03-14','Com','VER-EXC','Collaudo')
    Query used
    SELECT *
      FROM (SELECT eq_id,
                   date_completed,
                   RANK ()
                   OVER (PARTITION BY eq_id
                         ORDER BY date_completed DESC NULLS LAST)
                      rn
              FROM wrhwr
             WHERE     status != 'S'
                   AND pmp_id LIKE 'VER-EX%'
                   AND description LIKE '%Verifica%') table1,
           (SELECT eq_id,
                   date_completed,      
                   RANK ()
                   OVER (PARTITION BY eq_id
                         ORDER BY date_completed DESC NULLS LAST)
                      rn
              FROM wrhwr
             WHERE     status != 'S'
                   AND pmp_id LIKE 'VER-EX%'
                   AND description LIKE '%Revisione%') table2,
           (SELECT eq_id,
                   date_completed,           
                   RANK ()
                   OVER (PARTITION BY eq_id
                         ORDER BY date_completed DESC NULLS LAST)
                      rn
              FROM wrhwr
             WHERE     status != 'S'
                   AND pmp_id LIKE 'VER-EX%'
                   AND description LIKE '%Collaudo%') table3
    WHERE     table1.eq_id = table3.eq_id
           AND table2.eq_id = table3.eq_id
           AND table1.eq_id = table2.eq_id
    Purpose of the above query is to selfjoin wrhwr table 3 times in order to have for every row:
    eq_id;
    completition date of a work request of type Verifica for this eq_id (table1 alias);
    completition date of a wr of type Revisione (table2 alias) for this eq_id;
    completition date of a wr of type Collaudo (table3 alias) for this eq_id;
    A distinct eq_id:
    can have many work requests (wrhwr records) with different completition dates or without completition date (date_completed column NULL);
    in a date range can have all the types of wrhwr ('Verifica', 'Revisione', 'Collaudo') or some of them (ex. Verifica, Revisione but not Collaudo, Collaudo but not Verifica and Revisione, etc.);
    substrings in description shouldn't repeat;
    (eq_id,date_completed) aren't unique but (eq_id,date_completed,description,pmp_id) should be unique;
    Expected output
    Using sample data above I expect this output:
    eq_id,table1.date_completed,table2.date_completed,table3.date_completed
    MI-EXT-001,2013-07-01,2013-07-16,2013-03-14 <--- for this eq_id table3 doesn't have 3 rows but only 1. I want to repeat the most ranked value of table3 for every result row
    MI-EXT-001,2013-07-01,2013-06-15,2013-03-14 <-- I don't wanna this row because table1 and table2 have both 3 rows so the match must be in rank terms (1st,1st) (2nd,2nd) (3rd,3rd)
    MI-EXT-001,2013-06-25,2013-06-15,2013-03-14 <-- 2nd rank of table1 joins 2nd rank of table2
    MI-EXT-001,2013-04-30,2013-04-14,2013-03-14 <-- 1st rank table1, 1st rank table2, 1st rank table3
    In vector style syntax, expected tuple output must be:
    ix = i-th ranking of tableX
    (i1, i2, i3) IF EXISTS an i-th ranking row in every table
    ELSE
    (i1, b, b)
    where b is the first available lower ranking of table2 OR NULL if there isn't any row  of lower ranking.
    Any clues?
    With the query I'm unable to remove "spurius" rows.
    I'm thinking at a solution based on analytic functions like LAG() and LEAD(), using ROLLUP() or CUBE(), using nested query but I would find a solution elegant, easy, fast and easy to maintain.
    Thanks

    FrankKulash ha scritto:
    About duplicate dates: I was most interested in what you wanted when 2 (or more) rows with the same eq_id and row type (e.g. 'Collaudo') had exactly the same completed_date.
    In the new results, did you get the columns mixed up?  It looks like the row with eq_id='MI-EXT-0002' has 'Collaudo' in the desciption, but the date appears in the verifica column of the output, not the collaudo  column.
    Why don't you want 'MI-EXT-0001' in the results?  Is it realted to the non-unique date?
    For all optimization questions, see the forum FAQ:https://forums.oracle.com/message/9362003
    If you can explain what you need to do in the view (and post some sample data and output as examples) then someone might help you find a better way to do it.
    It looks like there's a lot of repetition in the code.  Whatever you're trying to do, I suspect there's a simpler, more efficient way to do it.
    About Duplicate dates: query must show ONLY one date_completed and ignore duplicated. Those records are "bad data". You can't have 2 collaudos with the same date completed.
    Collaudo stands for equipment check. A craftperson does an equipment check once a day and, with a mobile app, update the work request related to equipment and procedure of preventive maintenance, so is impossibile that complete more than one check (Collaudo) in a day, by design.
    In the new results, it's my fault: during digitation I've swapped columns
    With "I don't want 'MI-EXT-0001'" I mean: "I don't want to show AGAIN MI-EXT-0001. In the previous post was correct the output including MI-EXT-0001.
    Regarding optimisation...
    repetition of
    LAST_VALUE ( 
                            MIN (CASE WHEN r_type = THEN column_name END) IGNORE NULLS) 
                         OVER (PARTITION BY eq_id ORDER BY r_num)  AS alias_column_name
    is because I don't know another feasible way to have all columns needed of table wrhwr in main query, maintaining the correct order. So i get them in got_r_type and propagate them in all the subquery.
    In main query I join eq table (which contains all the information about a specific equipment) with "correct" dates and columns of wrhwr table.
    I filter eq table for the specific equipment standard (eq_std column).
    efm_eq_tablet table and where clause
    AND e.eq_id = e2.eq_id 
              AND e2.is_active = 'S'; 
    means: show only rows in eq table that have an equal row in efm_eq_tablet table AND are active (represented by 'S' value in is_active column).
    About the tables v2, r2 and c2
              (SELECT doc_data, doc_data_rinnovo, eq_id 
                 FROM efm_doc_rep edr 
                WHERE edr.csi_id = '1011503' AND edr.doc_validita_temp = 'LIM') v2, 
              (SELECT doc_data, doc_data_rinnovo, eq_id 
                 FROM efm_doc_rep edr 
                WHERE     eq_id = edr.eq_id 
                      AND edr.csi_id = '1011504' 
                      AND edr.doc_validita_temp = 'LIM') r2, 
              (SELECT doc_data, doc_data_rinnovo, eq_id 
                 FROM efm_doc_rep edr 
                WHERE     edr.csi_id IN ('1011505', '1011507') 
                      AND edr.doc_validita_temp = 'LIM' 
                      AND adempimento_ok = 'SI') c2, 
    Those tables contains "alternate" dates of completition to be used when there isn't any wrhwr row for an eq_id OR when all date_completed are NULL.
    NVL() and NVL2() functions are used in main query in order to impletement this.
    The CASE/WHEN blocks inside main query implements the behavior of selecting the correct date based of the above conditions.

  • Alternative to find unique records with 60 character in selection string.

    Hi,
    We have to find out the values from the Infoobject. When we try to display data from an master object, the maximum length of selection it accepts 45 characters only but we need to input data around 60 characters in selection.
    Thing we tried:
    1. Selecting complete data without any condition but it did not work due to large volume of data.
    2. We tried to extract data from RSA3 but it did not work due to large volume of data.
    Please suggest me alternative to find unique records with 60 character in selection string.
    Regards,
    Himanshu Panchal.

    This sounds a bit strange. Are you perhaps mistakenly storing text data incorrectly as the primary key of the master data? I can't think of any actual data that is that length to ensure usinqueness - even GUIDs are maximum 32 characters - but GUIDs don't count as actual "readable" data although you do need to be able to select it from time to time. Perhaps you have a super secure password hash or something like it ?
    Also are you expecting to have a unique single record returned by your selection? To do this would in general REQUIRE that ALL the data is read because master data is not stored in the DB sorted by the data itself, but stored instead sorted by the it's SID.
    When you say you are selecting data from master data, which master data tables are you using? I have been able to select data from very large MD table (15 million unique records) using SE16 with no problems. Just enter the table name, and before you execute just count the number of records - it helps to know what you want to end up with.
    Have you tried using wild cards (the *) to preselect a smaller number of records : * a bit of your 60 character string *
    If you are trying to select from a non-key field you will encounter performance issues, but you can still use the wildcards, and get a result.
    Don't use RSA3 it was designed to make selections and group them into datapackets. It's not the same as selecting directly on the table in SE11 or SE16

  • How to get most recent consecutive records with the same value

    Hi,
    Can someone please help me to solve my problem?
    Below is my table
    Prod_Code-----Purchase_date---Inv_number-------Inv_amt
    MS_AV16850------18/01/2005-----------6575947----------------7.93
    MS_AV16850------22/07/2005-----------7034012----------------51.82
    MS_AV16850------04/01/2006-----------8719618----------------51.82
    MS_AV16850------20/06/2006-----------9515864----------------104.69
    MS_AV16850------16/04/2007-----------10353759----------------189.29
    MS_AV16850------30/05/2007-----------10689899----------------189.29
    MS_AV16850------06/01/2008-----------1653821----------------65.49
    MS_AV16850------22/02/2009-----------10866311----------------189.29
    I want my query to show the rows that has most recent purchase dates with same amount in consecutive purchase date.
    So from the table above, the query should display:
    Prod_Code-----Purchase_date---Inv_number-------Inv_amt
    MS_AV16850------16/04/2007-----------10353759----------------189.29
    MS_AV16850------30/05/2007-----------10689899----------------189.29
    It should not get
    MS_AV16850------16/04/2007-----------10353759----------------189.29
    MS_AV16850------30/05/2007-----------10689899----------------189.29
    MS_AV16850------22/02/2009-----------10866311----------------189.29
    because inv_number 10866311 has a prvevious inv_amount of 65.49.
    and not get this
    MS_AV16850------22/07/2005-----------7034012----------------51.82
    MS_AV16850------04/01/2006-----------8719618----------------51.82
    because they are not the most recent purchase date even if they have the same inv_amount.
    Thanks in advance.

    Hi,
    You're right; thanks for catching my mistake.
    I changed the WHERE clause of the main query (including subquery there) to deal with that situation:
    WITH     got_grp          AS
         SELECT      x.*
         ,      ROW_NUMBER () OVER ( ORDER BY      purchase_date )
                - ROW_NUMBER () OVER ( PARTITION BY  inv_amt
                                             ORDER BY         purchase_date )     AS grp
    --     ,      ROW_NUMBER () OVER ( ORDER BY      purchase_date )     AS r1
    --     ,        ROW_NUMBER () OVER ( PARTITION BY  inv_amt
    --                                         ORDER BY         purchase_date )     AS r2
         FROM     table_x     x
    SELECT     *     -- Or list all columns except grp
    FROM     got_grp
    WHERE     (inv_amt, grp)  IN  (
                               SELECT    MAX (inv_amt) KEEP (DENSE_RANK LAST ORDER BY MAX (purchase_date))
                        ,       MAX (MAX (grp))
                                FROM      got_grp
                                GROUP BY  grp
                                ,       inv_amt
                                HAVING    COUNT (*)     > 1
    ;Thanks, too, for posting the sample data. Apparantly, you're more interested in solving this problem than OP is.
    Edited by: Frank Kulash on Nov 22, 2010 1:36 PM
    The r1 and r2 columns are not needed for the solution. You may want to display them, just to help see how the query works.

  • Same set of Records not in the same Data package of the extractor

    Hi All,
    I have got one senario. While extracting the records from the ECC based on some condition I want to add some more records in to ECC. To be more clear based on some condition I want to add addiional lines of data by gving APPEND C_T_DATA.
    For eg.
    I have  a set of records with same company code, same contract same delivery leg and different pricing leg.
    If delivery leg and pricing leg is 1 then I want to add one line of record.
    There will be several records with the same company code contract delivery leg and pricing leg. In the extraction logic I will extract with the following command i_t_data [] = c_t_data [], then sort with company code, contract delivery and pricing leg. then Delete duplicate with adjustcent..command...to get one record, based on this record with some condition I will populate a new line of record what my business neeeds.
    My concern is
    if the same set of records over shoot the datapackage size how to handle this. Is there any option.
    My data package size is 50,000. Suppose I get a same set of records ie same company code, contract delivery leg and pricing leg as 49999 th record. Suppose there are 10 records with the same characteristics the extraction will hapen in 2 data packages then delete dplicate and the above logic will get wrong. How I can handle this secnaio. Whether Delta enabled function module help me to tackle this. I want to do it only in Extraction. as Data source enhancement.
    Anil.
    Edited by: Anil on Aug 29, 2010 5:56 AM

    Hi,
    You will have to do the enhancement of the data source.
    Please follow the below link.
    You can write your logic to add the additional records in the case statement for your data source.
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/c035c402-3d1a-2d10-4380-af8f26b5026f?quicklink=index&overridelayout=true
    Hope this will solve your issue.

  • How to find a selection of photos taken at different dates but imported together. I want them in the same album but they're no longer in the "last import" album.

    I imported a bunch of photos taken at different dates that i wanted to group together in the same album but they are not in the "last import" album and are all just mixed in with "all photos" according to the dates they were taken and it's impossible to sift through them all to select the ones i wanted.

    Sorry I'm terrible at explaining and even using my macbook haha. Let me try again. I imported some photos that I wanted to group together into an album. I forgot to create the album before importing a new set of photos which then took the place of the previous ones in the "last import" album. Is there anywhere or any way I can easily find the selection of photos I forgot to put into an album together without having to select them one by one from the "all photos" section? These would be the only pictures in my Photos application that haven't been organized into an album yet if that helps; however, these photos were not taken on the same date.

  • I want to upgrade iOS from 5 to 6, but when I go to synch everything in preparation, it tells me I will lose all my stuff on the iPhone and iPad which is unique.  How can I backup or do a "real synch" (both sides have same data) and then upgrade?

    I want to upgrade iOS from 5 to 6, but when I go to synch everything in preparation, it tells me I will lose all my stuff on the iPhone and iPad which is/are  unique.  How can I backup or do a "real synch" (both sides have same data at end of process) and then upgrade?

    You should really read the manual.
    "How do you restore from backup? "
    Restore.  When given the choice, choose to use backup.
    "And how can I check to see if the pics and videos are on my computer somewhere first??"
    They would only be where you put them.  What program did you use to import them?  Pics/vids taken with ipod are not part of the sync process at all.  You should be importing them just as you would with any digital camera.
    If you did not import them, then they are not on your computer.

  • "record enable" buttons not showing up in Garage Band 10.0.3 (I have selected "show record enable"- a space in the track header opens up, but the button is not present.  Same with "input moniter".

    "record enable" buttons not showing up in Garage Band 10.0.3 (I have selected "show record enable"- a space in the track header opens up, but the button is not present.  Same with "input monitor".

    Look at all the posts in the forum from users with similar problems, it happened with the last Logic update.

  • How to restrict or stop the same data provided in selection screen parameters its should stop fetch the data on previously provided data?

    Hi Developer,
    i have issues that i need stop or restrict the same entries provided in the selection screen parameters it should no display that data but it should give an alert message by saying the data all ready viewed or displayed.
    example: organisation :getha pvt.td.
                  name :ramesh.
                  start date:10.2.2013.
    these are parameter which has been displayed by clicking execute ,if provide the same value to display again it should give waring message.
    Please guide me in solve the problem.
    thanks.
    ravi.

    Hi Somendra,
    Thanks for your response sir , i have provided the according to your provided information sir  but it was not  displaying the data first time also its giving message which i have provided ,my issues is if i provide data from time should display if i provide same data next time then only it should restrict the data and give a message.
    example:
    types:BEGIN OF str1,
       ROOMNO type zROOMNO,
       NAME TYPE zname3,
      BRANCH type zBRANCH,
       PHONENUMBER type zPHONENUMBER,
       END OF str1.
       data:it_str1 type TABLE OF str1,
            wa_str1 type str1.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME .
         skip.
    PARAMETERS:s_roomno type ZTABLE_2-roomno.
    skip.
    parameters:s_name type ztable_2-name.
    skip.
    PARAMETERS:s_branch type ztable_2-branch.
    skip.
    PARAMETERS:s_pho type ztable_2-phonenumber.
    SELECTION-SCREEN END OF BLOCK b1.
    AT SELECTION-SCREEN.
    SELECT  roomno
             name
             branch
             phonenumber from ztable_2 into TABLE it_str1
             WHERE roomno eq s_roomno and name eq s_name and branch eq s_branch and phonenumber eq s_pho.
       READ TABLE it_str1 INTO wa_str1 with KEY roomno = s_roomno name = s_name branch = s_branch phonenumber = s_pho.
       if sy-subrc eq 0.
         MESSAGE 'THE DATA IS ALL READY VIEWED' TYPE   'E'.
         RETURN.
         ENDIF.
         START-OF-SELECTION.
       SELECT  roomno
             name
             branch
             phonenumber from ztable_2 into TABLE it_str1
             WHERE roomno eq s_roomno and name eq s_name and branch eq s_branch and phonenumber eq s_pho.
         loop at it_str1 into wa_str1.
         WRITE:/1 wa_str1-roomno,
                10 wa_str1-name,
                30 wa_str1-branch,
               60 wa_str1-phonenumber.
         ENDLOOP.
    please guide me in solving the issue sir.
    thanks,
    Ravi

  • Select Expert Record. Last 6 months and week start date on Monday

    Hello,
    i am trying to use the select expert record to grab the last 6 months worth of data. I require the week start day to be a monday and end on a sunday.
    Can someone please provide some advice the best way to do this
    kind regards
    david

    Hello Abhilash,
    Once again thanks for your reply.
    Yes this is correct, when it goes back 6 months i need it to skip the days prior and begin on a monday as we are reporting on a mon-sunday basis.
    I have tried your formula Date field >= dateadd('m',-6,currentdate) and it seems to grab 6 months of data, but the group weeks are not grouping from Monday to Sunday...
    kind regards
    david
    Edited by: davitali on Dec 2, 2011 9:35 AM

  • Select record having most recent date

    Table: Order
    Code     ImportId     EntryDate
    1 100
    10/11/2014
    1 101
    10/14/2014
    1 102
    10/10/2014
    2  103  10/11/2014
    2   104  10/15/2014
    I want to select the record having the most recent EntryDate grouped by Code. In the select, i need to return the ImportId.
    Anonymous

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Nothing you posted
    was right. Temporal data should use ISO-8601 formats. This is the only format allowed in the ANSI-ISO SQL Standards and it is the most common IT standard on Earth; but you do not know it! 
    Code should be in Standard SQL as much as possible and not local dialect. There is no such crap as a generic “code” in RDBMS. Table have keys, so you have no table! Rows are not records; this is a basic concept. 
    This is minimal polite behavior on SQL forums. Here is my guess at what a polite, competent person might have posted. 
    CREATE TABLE Import_Orders
    (order_type INTEGER NOT NULL
     CHECK(order_type IN (1,2)),
     import_id CHAR(3) NOT NULL PRIMARY KEY, 
     entry_date DATE NOT NULL);
    INSERT INTO Import_Orders
    VALUES
    (1, 100, '2014-10-11'),
    (1, 101, '2014-10-14'),
    (1, 102, '2014-10-10'),
    (2, 103, '2014-10-11'),
    (2, 104, '2014-10-15');
    I want to select the record [sic] having the most recent entry_date grouped by order_type. In the select, I need to return the import_id.
    If you return only the import_id, then the most recent entry_date does not matter! Think about it! Did you want the whole row with the most recent entry_date? Here is a common idiom. 
    WITH X (import_id, order_type, entry_date, entry_date_max)
    AS
    (SELECT import_id, order_type, entry_date, 
            MAX(entry_date) OVER (PARTITION BY order_type)
       FROM Import_Orders) 
    SELECT import_id, order_type, entry_date
      FROM X
     WHERE entry_date = entry_date_max;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

Maybe you are looking for

  • Morphing Plug-ins for Premiere Pro

    I have been tasked to produce a video which will require a morphing effect between 2 individuals. I know that since this is not new technology (music videos in the 80s) there are many plug-in products to be found, but has anyone found one that is bot

  • Output of the time command

    Hi, I have simple program, which sends some commands throught TCP/IP and waits for reply. I would like to measure time spent on the other side to reply, so as the first try, I run it using time command. Output surprised me, ratio between real time an

  • IPhoto to Aperture Questions

    I currently have over 17,000 photos in iPhoto.  I really need something more to organize my photos.  I have downloaded the trial version of Aperture and have imported my iPhoto library (referenced).  What are the advantages/disadvantages of reference

  • BP sales area

    Hi I have a BP that is assigned to 2 sales areas..How do I delete one of the sales areas from the BP. I am in "change" mode for the BP, the sales area dropdown shows 2 values. How do I delete one? Thanks

  • SAP SCRIPT DUPLEX PRINTING

    i am trying to print a production order ( Z sap script ) which has materials and other info span over 2 to 3 pages .i want to print this both sides of the paper. this sap script has a single page and a single window ... how do i get this form printed