Pulling records where number of records for unique ID = 6

I have a table that contains address information for everyone in the system. It has numerous fields, though I've only included a few in the create table query below for the sake of brevity. The PIDM uniquely identifies each record as belonging to a particular person in the database. A person can have multiple addresses in the table, though we normally do not allow them to have more than one active address of a particular ATYP_CODE. Again, I am doing this here for the sake of brevity. What I need to do is pull all the records for each PIDM, but only where there are >= 6 records per PIDM. The user doesn't care if the data are pivoted (I can do that part if needed). Pulling the actual data isn't the issue. I just need a little help figuring out how to get only the records of PIDMs with six or more records in the table. So, from the example data below, the records for PIDM 12345 and 34567 are the ones that should be in the output, but the ones from PIDM 23456 should not.
DROP TABLE SPRADDR;
CREATE TABLE SPRADDR
(PIDM              NUMBER(8),
ATYP_CODE     VARCHAR2(2 CHAR),
STREETLINE1   VARCHAR2(60 CHAR),
CITY              VARCHAR2(60 CHAR),
STATE              VARCHAR2(2 CHAR),
ZIP              VARCHAR2(10));
INSERT INTO SPRADDR VALUES (12345,'PR','1 MAIN','CANFIELD','OH','44406');
INSERT INTO SPRADDR VALUES (12345,'MA','1 MAIN','CANFIELD','OH','44406');
INSERT INTO SPRADDR VALUES (12345,'BU','1 MAIN','CANFIELD','OH','44406');
INSERT INTO SPRADDR VALUES (12345,'PR','2 MAIN','CANFIELD','OH','44406');
INSERT INTO SPRADDR VALUES (12345,'MA','3 MAIN','CANFIELD','OH','44406');
INSERT INTO SPRADDR VALUES (12345,'PR','4 MAIN','CANFIELD','OH','44406');
INSERT INTO SPRADDR VALUES (23456,'PR','1 MAIN','KENT','OH','44240');
INSERT INTO SPRADDR VALUES (23456,'MA','1 MAIN','KENT','OH','44240');
INSERT INTO SPRADDR VALUES (23456,'BU','1 MAIN','KENT','OH','44240');
INSERT INTO SPRADDR VALUES (34567,'PR','1 MAIN','CANFIELD','OH','44406');
INSERT INTO SPRADDR VALUES (34567,'MA','1 MAIN','CANFIELD','OH','44406');
INSERT INTO SPRADDR VALUES (34567,'BU','1 MAIN','CANFIELD','OH','44406');
INSERT INTO SPRADDR VALUES (34567,'PR','2 MAIN','CANFIELD','OH','44406');
INSERT INTO SPRADDR VALUES (34567,'MA','3 MAIN','CANFIELD','OH','44406');
INSERT INTO SPRADDR VALUES (34567,'PR','4 MAIN','CANFIELD','OH','44406');
INSERT INTO SPRADDR VALUES (34567,'PR','6 MAIN','CANFIELD','OH','44406');
COMMIT;I'd greatly appreciate any help you might be able to provide. I'm sure this is easy, but what I've done so far has not worked and I'm not including the code I tried because it's totally cockeyed and not working at all.
Thanks,
Michelle Craig
Data Coordinator
Admissions Operations and Transfer Systems
Kent State University

PIDM 12345 and 34567 are the ones that should.Why 12345? It is repeated 6 times where you asked for > 6. Anyway:
SQL> select  *
  2    from  (
  3           select  s.*,
  4                   count(*) over(partition by pidm) cnt
  5             from  spraddr s
  6          )
  7    where cnt > 6
  8    order by pidm
  9  /
      PIDM AT STREETLINE1     CITY                 ST ZIP               CNT
     34567 PR 1 MAIN          CANFIELD             OH 44406               7
     34567 MA 1 MAIN          CANFIELD             OH 44406               7
     34567 BU 1 MAIN          CANFIELD             OH 44406               7
     34567 PR 2 MAIN          CANFIELD             OH 44406               7
     34567 MA 3 MAIN          CANFIELD             OH 44406               7
     34567 PR 4 MAIN          CANFIELD             OH 44406               7
     34567 PR 6 MAIN          CANFIELD             OH 44406               7
7 rows selected.
SQL> select  *
  2    from  (
  3           select  s.*,
  4                   count(*) over(partition by pidm) cnt
  5             from  spraddr s
  6          )
  7    where cnt >= 6
  8    order by pidm
  9  /
      PIDM AT STREETLINE1     CITY                 ST ZIP               CNT
     12345 PR 1 MAIN          CANFIELD             OH 44406               6
     12345 MA 1 MAIN          CANFIELD             OH 44406               6
     12345 BU 1 MAIN          CANFIELD             OH 44406               6
     12345 PR 2 MAIN          CANFIELD             OH 44406               6
     12345 MA 3 MAIN          CANFIELD             OH 44406               6
     12345 PR 4 MAIN          CANFIELD             OH 44406               6
     34567 PR 1 MAIN          CANFIELD             OH 44406               7
     34567 MA 1 MAIN          CANFIELD             OH 44406               7
      PIDM AT STREETLINE1     CITY                 ST ZIP               CNT
     34567 BU 1 MAIN          CANFIELD             OH 44406               7
     34567 PR 2 MAIN          CANFIELD             OH 44406               7
     34567 MA 3 MAIN          CANFIELD             OH 44406               7
     34567 PR 4 MAIN          CANFIELD             OH 44406               7
     34567 PR 6 MAIN          CANFIELD             OH 44406               7
13 rows selected.
SQL>  SY.
Edited by: Solomon Yakobson on May 10, 2012 10:02 AM

Similar Messages

  • Program Process chain-- Number of records per day.

    Hi  Friends,
    i need to  develop a program based   upon the below template.
    Chain Name      Start Date     Start Time   End Date      End Time     Total Run Time    Number of Records      Total number of records
                                                                                    IP1/IP2/IP3
    Imgaine that i have a process chain with 3 infocpakages..
    Please help us in having the code as i donot know ABAP and program /ssa/bwt will not survive my purpose.\
    Regards,
    Siddhu

    hi sid,
    i think while creating the abap code u need to take help of following tables:-
    Chain Name              RSPCLOGCHAIN.  take chain id from corresponding Chain name, and navigate to table RSPCPROCESSLOG.
    Start Date                          RSPCPROCESSLOG
    Start Time                          RSPCPROCESSLOG
    End Date
    End Time                           RSPCPROCESSLOG
    Total Run Time                  can be caluted using ENDSTAMP and STARTTIME.
    Number of Records          RSMONICDP
    Total number of records   RSMONICDP
    you have to hit these table and take the latest data from your abap code.
    thanks

  • Number of records being pulled from OLAP/ SQL in BPC 5.1

    Hello BPC gurus,
                         We are experience performance issues with EVDRE.basically the report errors out and the error log states " Decompressing request failed". We are in BPC 5.1
           We were trying to understand how many number of records the evdre is pulling from from OLAP / database  so that we can look into some fine tuning opportunities of the EVDRE. 
          In the BI world we have RSRT where in which we can view the number of records from database, number of records transferred. Is there any such feature in BPC, where in which we can information on record counts.
    We have turned on the error logs , but none of them give us an idea of the record count.
    Appreciate your help in advance.
    Thanks
    sai

    Hi Sorin,
                   Thank you very much for getting to me on my clarificaiton on the record count. As per your suggestion, we have already looked into this OSS note, and changed the entries in the table. After making these changes, the queries that normally execute in 1 min, now take 30 minutes to complete. Believe this was the observation also in some of the threads related to this issue. 
    You had mentioned that there might be an issue with the communication between application server  and BPC Client. or SQE generating MDX query.  Can you please give us some pointers on how to investigate this. Have turned on error logs evdataserver_debug.txt & EVDATASERVER_TRACE.txt on the file server,  but i believe there is an OSS note 1311019, that talks about these logs not workign with SP9.
    If you can guide us in the folllowing that would be helpful
    1  how to bebug this issue that we are currently facing.
    2. How does the concept of compressing / decompressing work in BPC.
    Thanks
    sai

  • SQL help: return number of records for each day of last month.

    Hi: I have records in the database with a field in the table which contains the Unix epoch time for each record. Letz say the Table name is ED and the field utime contains the Unix epoch time.
    Is there a way to get a count of number of records for each day of the last one month? Essentially I want a query which returns a list of count (number of records for each day) with the utime field containing the Unix epoch time. If a particular day does not have any records I want the query to return 0 for that day. I have no clue where to start. Would I need another table which has the list of days?
    Thanks
    Ray

    Peter: thanks. That helps but not completely.
    When I run the query to include only records for July using a statement such as following
    ============
    SELECT /*+ FIRST_ROWS */ COUNT(ED.UTIMESTAMP), TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY') + (ED.UTIMESTAMP/86400)), 'MM/DD') AS DATA
    FROM EVENT_DATA ED
    WHERE AGENT_ID = 160
    AND (TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY')+(ED.UTIMESTAMP/86400)), 'MM/YYYY') = TO_CHAR(SYSDATE-15, 'MM/YYYY'))
    GROUP BY TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY') + (ED.UTIMESTAMP/86400)), 'MM/DD')
    ORDER BY TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY') + (ED.UTIMESTAMP/86400)), 'MM/DD');
    =============
    I get the following
    COUNT(ED.UTIMESTAMP) DATA
    1 07/20
    1 07/21
    1 07/24
    2 07/25
    2 07/27
    2 07/28
    2 07/29
    1 07/30
    2 07/31
    Some dates donot have any records and so no output. Is there a way to show the missing dates with a COUNT value = 0?
    Thanks
    Ray

  • To count number of records in an internal table for a condition

    Hello All,
            I want to count number of records in an internal table for a condition.
    For e.g. -- I have one internal table IT which having fields F1, F2, F3, F4, F5.
                     Now, I want number of records in itnternal table IT where F1 = 'ABC'.
    Is it possible to do..?? If yes, then how.??
    Thanks in advance...!!
    Regards,
    Poonam.

    Hi,
    If you mean an internal table, there are a few ways to do this.
    1 One would be to loop over the table with a WHERE clause and increment a counter.
    data: lv_counter type i.
    clear lv_counter.
    loop at itab where fld1 = 'ABC'.
    lv_counter = lv_counter + 1.
    endloop.
    lv_counter now has the number of rows per the condiction.
    2  Well, you may want to try this as well, and compare to the LOOP way. Not sure what kind of overhead you may get doing this way. Here ITAB is our main internal table, and ITAB_TMP is a copy of it. Again I think there may be some overhead in doing the copy. Next, delete out all records which are the reverse of your condition. Then whatever is left is the rows that you want to count. Then simply do a LINES operator on the internal table, passing the number of lines to LV_COUNT.
    data: itab type table of ttab.
    data: itab_tmp type table of ttab.
    itab_tmp[] = itab[].
    delete table itab_tmp where fld1  'ABC'.
    lv_count = lines( itab_tmp ).
    Thanks & Regards,
    ShreeMohan

  • BI Loading for Infoobject : Number of records

    Hi Experts,
    When i am loading the data from DS 0wbs_elemt_attr to Infoobject 0wbs_elemt, in rsa3 there are 102117 number of records. but when i run the infopackge i see the number of records are 102035. I would like to know if there are any checkpoints to check as to where should I check for less number of records that are coming up.
    Kindly advise.
    thanks & regards,
    M.S

    Hi experts,
    I deleted everything and reloaded. It is now reflecting 1020117 number of records(dont know how).
    Thankyou guys for your help. Assigned points.
    thanks & regards,
    M.S
    Edited by: M.S on May 7, 2010 12:14 PM

  • Maximum number of records for usage of "For all entries"

    Hi,
    Is there a limit on maximum number of records to be selected from the database using "For all entries"  statement ?
    Thanks in advance

    There is a UNDOCUMENTED(??) behaviousr
    FOR ALL ENTRIES does ahidden SELECT DISTINCT & drops duplicates.
    http://web.mit.edu/fss/dev/abap_review_check_list.htm
    3 pitfalls
    "FOR ALL ENTRIES IN..." (outer join) are very fast but keep in the mind the special features and 3 pitfalls of using it.
    (a) Duplicates are removed from the answer set as if you had specified "SELECT DISTINCT"... So unless you intend for duplicates to be deleted include the unique key of the detail line items in your select statement. In the data dictionary (SE11) the fields belonging to the unique key are marked with an "X" in the key column.
    ^^!!!!
    (b) If the "one" table (the table that appears in the clause FOR ALL ENTRIES IN) is empty, all rows in the "many" table (the table that appears in the SELECT INTO clause ) are selected. Therefore make sure you check that the "one" table has rows before issuing a select with the "FOR ALL ENTRIES IN..." clause.
    (c) If the 'one' table (the table that appears in the clause FOR ALL ENTRIES IN) is very large there is performance degradation Steven Buttiglieri created sample code to illustrate this.

  • CLIENT_TEXT_IO - Hanging on "PUT" for large number of records

    I have successfully used CLIENT_TEXT_IO but my users have run into an error where the Form hangs and spits out details such:
    "oracle.forms.net.HTTPNStream.doFlush"
    etc....
    This happens when the number of records in the datablock is high (ex: 70,000 recs). So my question is: Is there a limit on how many lines you can write to a file?
    I'm just creating a CSV file on the client's machine using CLIENT_TEXT_IO.PUT_LINE. It works fine on say a few thousand recs but after that it hangs.
    I'm on Oracle Application Server 10g, Release 9.0.4 on Windows Server 2003, and forms compiled using Oracle Developer Suite 9.0.4.
    Thanks,
    Gio

    Hello,
    When playing with huge data, it is better to generate the file on the A.S. then get it back to the client.
    <p>Read this article</p>
    Francois

  • How to count number  of records for a field based on condition?

    Hi guys,
    I want to know how to find count of records coming from the database for a particular field based on some condition.
    I need to use this count to suppress some headers. Because of this i am not able to use running totals. Is there any other way?
    Ex scenario:
    I have account number and currency fields, those are coming from database. And i need to count the number of accounts whose currency is not Euro.
    Thanks in advance,
    Vijay.

    A simple formula can do that:
    //Formula begin
    if {your account field}<>"Euro" then 1
    //Formula end
    This formula can be summarized. (by group or report)
    Bryan Tsou@Taiwan

  • Change number of record displayed for a single item alone

    Hi,
    I have a single data block with few items. Is it possible to make one item in the block as non-database item and make the display of record in the item alone to show multiple lines.
    i.e. All other items in the Data block shows single record, whereas this particular item should shows 10 records.
    Is this achievable?
    Or should i have to put that item in a separate data block and choose the data block property to "Number of records displayed" as 10?
    Thanks,
    Yuvaraaj.

    983448 wrote:
    Hi,
    I have a single data block with few items. Is it possible to make one item in the block as non-database item and make the display of record in the item alone to show multiple lines.
    i.e. All other items in the Data block shows single record, whereas this particular item should shows 10 records.Yes you can. But i will say re-check your design.
    Hamid
    Mark correct/helpful to help others to get right answer(s).*

  • Different number of records in RSA3 for Full and INIT

    Hi All,
    I am about to load the data from 0FI_GL_4 and checked it in RSA3 for the number of records. It returned different number of records when I run the extract with options 'F' and 'C'. Why is it so? This is the first time I am loading the data into BW for this datasource. I would expect the number of records to be same if I do either a full extract or an init but surprised by seeing different number of records.
    Best Regards,
    James.

    Hi James,
    Probably it's because of the time stamps stored in table BWOM2_TIMEST.
    If you run a delta init and than a delta update then the number of the records should match with the record of the full update.
    You can find some more info about table BWOM2_TIMEST here:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/a7f2f294-0501-0010-11bb-80e0d67c3e4a#527,7,Timestamp%20Mechanism:%20New%20documents
    Bye,
         Zsolt

  • Number of Records in RSA3 for 0EC_PCA_1

    Dear all,
    I have installed data source 0EC_PCA_1 from content. Data for this data source is extracted from table GLPCT. When see at the table there are only 634 and number of records that are extracted from data source in RSA3 is 28203. I want to understand logic behind this or am I making any mistake.
    On source system side we are ECC 6.0 and 'New GL' Functionality has been activated.
    Request your help as usual.
    Regards
    SN Dubey

    You can try the function module ECPCA_BIW_GET_DATA in order to see what really happens; but it could take some time since it depends a lot on your customizing: if you use special ledgers, the balance carry forward stuff and a lot more...
    An you are correct: I thought straight forward about EC_PCA_3 (GLPCA) instead of EC_PCA_1 (GLPCT); my mistake, sorry for that.
    In any case I cannot tell how it works in ECC.
    regards

  • Max Number of records for BAPI 'BAPI_PBSRVAPS_GETDETAIL'

    Hi All,
    Can you suggest me the number of records to be fed to the 'BAPI_PBSRVAPS_GETDETAIL'.
    I am using a few location products for 9 key figures.Whenever number of records
    in selection table increases BAPI behaves in a strange way and the code written below it does not get executed.
    Please guide me to get full points.
    Thanks in Advance,
    Chandan Dubey

    Hi Uma,
        It comes out of the program after this code is executed.I have 50 location product combinations in vit_selection table.
      CALL FUNCTION 'BAPI_PBSRVAPS_GETDETAIL'
        EXPORTING
          planningbook                = planning_book
          period_type                 = 'B'
          date_from                   = l_from_week
          date_to                     = l_to_week
          logical_system              = logical_system
          business_system_group       = business_system_group
        TABLES
          selection                   = vit_selection
          group_by                    = vit_group_by
          key_figure_selection        = vit_kf_selection
          time_series                 = vit_t_s
          time_series_item            = vit_t_s_i
          characteristics_combination = vit_c_c
          return                      = vit_return.
      LOOP AT vit_return.

  • Max number of records for  'BAPI_PBSRVAPS_GETDETAIL'.

    Hi All,
    Can you suggest me the number of records to be fed to the 'BAPI_PBSRVAPS_GETDETAIL'.
    I am using a few location products for 9 key figures.Whenever number of records
    in selection table increases BAPI behaves in a strange way and the code written below it does not get executed.
    Please guide me to get full points.
    Thanks in Advance,
    Chandan Dubey

    Server memory issue !

  • Cursor for loop gives less number of records for certain condition

    Hi i am getting very weired behaviour of cursor for loop.
    i have one query below which returns 128 records.
    select su.item_id from suv_tmp su
    inner join review_items ri on su.ITEM_ID = RI.ITEM_ID
    inner join sources s on s.source_id=ri.source_id
    and s.source_name='XYZ'
    but when i take this query in cursor for loop it returns only 100 records.
    this is the cursor for loop i am writing:
    begin
    for v_rec in
    (select su.item_id from suv_tmp su
    inner join review_items ri on su.ITEM_ID = RI.ITEM_ID
    inner join sources s on s.source_id=ri.source_id
    where s.source_name='XYZ'
    loop
    dbms_output.put_line(v_rec.item_id);
    end loop;
    end;
    It prints only 100 records.
    The weired behaviour is that if i select any column name from the table which is used in where clause it gives 128 records..
    query below gives expected output
    begin
    for v_rec in
    (select su.item_id,s.source_descr from suv_tmp su
    inner join review_items ri on su.ITEM_ID = RI.ITEM_ID
    inner join sources s on s.source_id=ri.source_id
    where s.source_name='XYZ'
    loop
    dbms_output.put_line(v_rec.item_id);
    end loop;
    end;
    i am not able to find out any logc..
    Any pointers appreciated..
    Edited by: user11266153 on Dec 14, 2011 11:27 PM

    1) Can you provide the DDLs of those tables and dummy data to check if it gets reproduced at our env.
    2) What is the Oracle Database software version? e.g. 9iR2 , 10gR1 , 10gR2 , 11gR1 etc...

Maybe you are looking for