Drawing from records where the number of records of unique ID > = 6

I have a table that contains the address information for everyone in the system. It has many areas, although I have included only a few in the create table query below for brevity. The PIDM uniquely identifies each record as belonging to a person especially in the database. A person can have multiple addresses in the table, although normally, we do not allow them to have more than one active address of a particular ATYP_CODE. Yet once again, I do it here for brevity. What I have to do is to shoot all the records for each PIDM, but only when there are > = 6 records by PIDM. The user does not care if the data is rotated (I can do this part if necessary). Pulling on the actual data is not the issue. I just need a little help to find how to get only the records of PIDMs with six or more records in the table. So, according to the sample data below, records for PIDM 12345 and 34567 are those which should be in the output, but those of 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 would be very happy any help you might be able to provide. I'm sure it's easy, but I've done so far has not worked, and I'm not including the code, I've tried because it is quite fishy and not working do not at all.

Thank you
Michelle Craig
Data Coordinator
Admissions and transfer systems
Kent State University

PIDM 12345 and 34567 are those who should.

Why 12345? It is repeated 6 times where you asked > 6. In any case:

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.

Published by: Solomon Yakobson on 10 may 2012 10:02

Tags: Database

Similar Questions

  • How big a file can I send with track and send? Is there a storage limit, to the extent where the number of files, you can download? How many times you send/download files are purged?

    How big a file can I send with track and send? Is there a storage limit, to the extent where the number of files, you can download? How many times you send/download files are purged?

    Hi pjvconsulting,

    There is no restriction on the number of files that you can send.

    However, for a free & buy account you cannot exceed a limit of 5 GB and 20 GB storage, respectively.

    The size of a file may not exceed 2 GB.

    Kind regards

    Nicos

  • Where the number of positions?

    I see that the upgrade has deleted the number of positions of every signature of users. I know there is a ranking, but personally, I like to see how many posts a user has made and how ling, they were a part of the communities. There is valuable information in determining what someones credibility answer can be.

    Where exactly you expect / this information is missing? You can drag the pointer of the mouse on a user name to find the information you are requesting in the pop-up window.

    André

  • How to check the number of servers, a unique summer migrated database?

    Is it possible to check the information of the previous server where the database has been migrated.

    Ajay Vijayan wrote:

    The binaries have been transferred from the old server and grid has been installed in the new ASM migration server.

    Alert log is purged according to police.

    Ajay

    1. logically, it can not be followed from the point of view of database. Since when we migrated to new server we can just copy the data files and take the help of rman and migrate (hope you are aware)

    2. If we are not reset all the newspapers during the process, if we do it due to a problem we knew that the level of incarnation (date/time)

    3 database does not take care of these information

    4. perhaps there is an alternative, you can get it from 'DBA_HIST_DATABASE_INSTANCE '.

    that keeps INSTANCE_NAME and HOST_NAME... .When you database runs from host A for 6 months and then you moved to server 'B '.

    5 to start and next stop he will track this new server (provided during migration if you have made a rebound at this time, then you can have alteast moving day)

    6. IF you are looking for server then in the course of the interview you can bounce while patching so separate hostname is able to follow

    -Note - rest depends on the number of records that he takes for his life

    It may be useful

    -Pavan Kumar N

  • How can I prevent people from seeing where the email has passed since?

    How can I stop showing where email is transmitted from

    How can I stop showing where email is transmitted from

    Select and then delete the addresses in the e-mail message.

    And when you send an email if you do not want your visible list of recipients used the bcc function.

    http://ask-Leo.com/how_does_using_bcc_help_reduce_spam.html

  • Make a difference in the number of records

    Hello

    Oracle9.2
    Windows


    Table A - records - 627255 total

    I want to pass some basic criteria records to a new table TAB_B, but implementation difference in number of records before and after the move.

    SELECT COUNT (*) FROM TAB_A WHERE the TIMING < (SYSDATE-150)-* 539911 *.

    CREATE TABLE TAB_B AS SELECT * FROM TAB_A WHERE the TIMING < (SYSDATE-150)

    SELECT COUNT (*) FROM TAB_B-* 539934 *.

    What can be the reason?


    Regarding

    SYSDATE is not static. It keeps ticking with impatience...

    And I suspect that you have a few 'ticks' between the time you did the count (*) and the create table.

  • Matrix of distances: selection of values with the number of the column as a variable

    Hi all

    You wonder if SQL can do natively, let's go.

    I have a static table with the same amount of rows and columns, that changes forever; It represents the distances between locations (e.g. countries).
    It's basically a distance matrix (you can find a good example on Wikipedia ).

    My SQL statement must extract the distances of this matrix, based on the IDS of countries located in another table.
    Select a field is simple:

    SELECT * from cdistances where countryid =
    (select countryid from countries where upper (country) = upper (& getcountry));

    When I run the present, I get a line of all distances to all countries of the country I go when asked. But I would limit the outcome of a country of destination that I entered.

    Of course, a CASE statement would solve this nicely, but since we are talking more than 200 countries, which will become unmanageable.

    Another method that I approached is to use a variable as a column, as below:

    SELECT & getdestination of cdistances where countryid =
    (select countryid from countries where upper (country) = upper (& getcountry));

    It works well when I get directly the column identifier (manually from the keyboard) but I would like to automate even further.
    My names of columns in the matrix of distances are named as follows:
    countries1, countries2, countries3... country200 - where the number ID the real country, preceded by the constant string 'country '.
    So I tried to define a variable as a concat between 'country' and another variable:
    def getd2 = concat ("D2C", & testcountryid);
    Of course, it does not; the output of the script is:

    old: def getd2 = concat ('country', & testcountryid)
    New: def getd2 = concat ("country", 12)

    where I expected to be 'country12.

    I'm so little loss of thoughts. Maybe I'm pushing my train of thought in the wrong way, so I guess the general question would be: how to select a specific column of a table based on information outside the SQL statement dynamically?

    Hello

    I'm still confused.
    Is your table called chessking or testdistances, or you have 2 separate tables?

    I'm guessing that your single table is testdistances, and you want to pass a list of countryids, such as that of 3.1 to a query and get results as follows:

    `COUNTRYID  DISTANCE3  DISTANCE1
    ---------- ---------- ----------
             1         18         15
             3         13          1
    

    If so:

    DEFINE     country_list = "3,1"
    
    -- Preliminary Query, to set column_list
    COLUMN     column_list_col     NEW_VALUE column_list
    
    SELECT     'distance' || REPLACE ( '&country_list'
                               , ','
                         , ',distance'
                         )          AS column_list_col
    FROM    dual;
    
    -- Main Query
    SELECT     countryid
    ,     &column_list
    FROM     testdistances
    WHERE     countryid     IN (&country_list)
    ;
    

    Sorry, I'm out of time now. I'll explain more in a few hours.

  • interpolation again to continue where the last tween left?

    I have a clip with a tween on its X position on mouse over. This point will go up in the air on mouse... then fall and bounce on mouse over. For example, this could be a ball. My problem is that if if I mouse over this ball to lift into the air and then the mouse on... He'll do the interpolation any rebound but if I smile back on this front ball of the mouse on the Tween is complete interpolation will access the end and does not work properly. I have my sure there must be a post any on this already, but I was unable to locate a (sorry)... What I need to happen is for the mouse on interpolation from there where the mouse on tween left to. If the ball is wriggling on it will start to fall and then if back quiver on it immediately back into the air from where the mouse on tween left of... does that make sense? its really hard for me to explain this. Maybe an example is necessary. ( http://videos.sonicelectronix.com/cbennett/ball/ball.html )

    I think on the mouse on the balls that must depend on the mouse Y and mouse out in the X position, the ball must fall.  There are probably a few things that I do wrong here but if someone could point me to please you in the right direction would be great! Thank you

    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    
    var bounceTween:Tween;
    
    this.addEventListener(MouseEvent.MOUSE_OVER, ballOver, false,0,true);
    function ballOver(e:MouseEvent):void{
         bounceTween = new Tween( e.target, "y", None.easeNone,148,50,5);
    }
    
    this.addEventListener(MouseEvent.MOUSE_OUT, ballOut, false,0,true);
    function ballOut(e:MouseEvent):void{
         bounceTween = new Tween( e.target, "y", Bounce.easeOut,50,148,20);
    }
    
    

    Make one Tween to pick up where another left you normally specify just the starting point than the current value of the object: e.target.y rather than a fixed value.  I don't know if you can send the object like a movieclip in this case.

  • Try to count the number of records where some columns are met

    Using SQL in Toad against an Oracle table, I'm trying to count the number of records in a table where some columns are filled. For
    example, I need to know the total number of records from a table where

    ln_stop_cd is not null - 65000 records
    ln_process_cd is <>- 25000 0 records
    ln_opt_cd is not null - 7500 records

    and the record_type = "A".

    I know that the total individual records as described above. However, I do not know how
    the SQL to show for record_type = 'A' the total count is 97500 records. Any help would be
    appreciated.

    Hello

    It seems that the problem is that the indictment may overlap; You can count the same rank 0, 1, 2 or 3 times, depending on whether 0, 1, 2 or 3 of these 3 independent conditions are met.

    Try something like this:

    SELECT     COUNT (in_stop_cd)
          + COUNT (CASE WHEN in_process_cd  != 0        THEN 1 END)     -- this site doesn't like the other inequality operator
          + COUNT (in_opt_cd)        AS grand_total
    FROM    table1
    WHERE     dt          >= TO_DATE ('01-JUN-2011', 'DD-MON-YYYY')
    AND     dt          <  TO_DATE ('02-JUN-2011', 'DD-MON-YYYY')
    AND     record_type       = 'A'
    ;
    

    You want to make charges without making 3 assists separated through the table. The problem is the 3 original requests had slightly different WHERE clauses.
    Put these conditions in the WHERE clause and make other conditions apply only to the individual counties, either with a column instead of *, or using a CASE statement that contains the condition that applies only to the column.

    Also, the date is not a column name good. Do not compare the DATEs to strings. If your column is really a DATE and you want to ignore the hours, the minutes and seconds, then the best way is to compare the column with 2 other DATES, as shown above. It's more coding, but it is more efficient and more reliable.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
    You don't have to display a large amount of data. You can probably give an excellent example of this problem with only 5 or 10 rows of sample data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

    Published by: Frank Kulash, August 4, 2011 11:27

  • How to change the number of records from the 25 to the different number?

    Hi friends...
    Generally, table 25 records at a time, and if registration exceeds the number there is a next button appears below the table. I need to change the number of records? Help, please.

    Thank you

    Hello...

    Try this, in the instanceconfig.xml file,



    50

    It works...

    Thank you & best regards
    Kishore Guggilla

  • Gets the number of records in the report based on the input of the user on the date and the number of days.

    Hello

    I need where there are quick dashboard that selects the date, second interval column consists of >, <, = and the third column is seen number (in days)

    for example, the user enters: 12 18, 2015, <, 9. here I report who should get the data (records) 9 days earlier from the date specified (from 12/10/2015 to 18/12/2015).

    Similarly for > =.

    How to get there. I'm unable to write the script and I use the column date in my report. Ask that you please advice how to solve this problem.

    Please find below the screen for reference.

    timediff.jpg

    Kind regards

    Chandra Khalil.

    Hello

    Not exactly why you're doing the report this way. If the user must select, basically, a period of dates, would not easier to have a column of data with a between the operator and the user would select 2 dates (upper and lower intervals)?

    In any case, it is possible to achieve what you want to do as a result of your approach. You could use when's CASE and have a more complex filter, but I think that it is better to have a few nested filters where you use the range operator to determine what date filter that you use (see image below)

    Some notes about my filter. First of all, I am making the assumption that the operator is "=", then the number of days specified must be ignored and you just return the data for the selected date. You will notice also that in my filters, I got a cast so far, but if you are using a column that is already a timestamp so it won't be necessary.

    This should achieve what you want.

    See you soon,.

    Pedro

  • How to determine the number of records in a subquery

    I am fairly new to Oracle SQL, and would like to know if anyone has examples of how to perform the following operations:

    1. I would return the number of rows that exist in the following SQL statement below. This SQL will be part of a larger SQL statement and I will be passing in the EMPLID identifier in the subquery. The result must be a value showing the total number of records that correspond to the SQL below. "xyz" will be finally passing through the extension number of the employee by using a reference to the parent SQL... ie: jbe. POSITION_NBR
    2. My SQL:

    SELECT Cjbe. EMPLID OF PS_JOB cjbe
    WHERE cjbe. POSITION_NBR = "xyz".
    GROUP BY cjbe. EMPLID

    I would like to know how I can change the value of poarent to POSITION_NBR (I think I use jbe.) POSITION_NBR) total calls the EMPLID found in this subquery subquery and then return.

    Thanks for your help.

    Maybe I lack something, but isn't this just

    SELECT count (distinct empl_id) from ps_job where position_nbr =: some_position_nbr

  • Returns the number of records

    IM under the sub query, it returns the number of records, but how can I count the number of records is reurning?

    I use version 12.0.0.61 (toad for oracle)

    Thank you

    Select * from object

    where owner = 'FIRST '.

    AND OBJECT_TYPE = 'FUNCTION '.

    AND OBJECT_NAME LIKE '% FDR_ % '.

    If you want just the County

    select count(*)
      from all_objects
     where owner='PREMIER'
      AND OBJECT_TYPE='FUNCTION'
      AND OBJECT_NAME LIKE'%FDR_%'
    

    If you want the number on each line in addition to the line-level data

    select a.*, count(*) over () cnt
      from all_objects a
     where owner='PREMIER'
      AND OBJECT_TYPE='FUNCTION'
      AND OBJECT_NAME LIKE'%FDR_%'
    

    Justin

  • by comparing the number of records in the table child

    I have 3 tables below:

    Table 1 - Parent Table
    Table table2 child - who has the number of records for each record in Table1 (row_id in Table1 corresponds to par_row_id in Table2)
    Child table table 3 - has that number of records for each record in Table1 (row_id in Table1 corresponds to par_row_id in table 3)

    I would like to run an Oracle SQL query to identify all the separate row_id on Table1, for which the number of child records in Table2 does not match the number of child records in Table3

    I ask for help to identify the best way to identify these records in the parent table. If possible an example too, please.

    Thank you

    Published by: cseshan on February 3, 2013 01:35

    All by adding the simplest example (with the sample data that you were supposed to provide) below

    create table table1(row_id number primary key);
    
    create table table2(par_row_id number references table1);
    
    create table table3(par_row_id number references table1);
    
    insert into table1 values(1);
    insert into table2 values(1);
    insert into table3 values(1);
    
    insert into table1 values(2);
    insert into table2 values(2);
    insert into table2 values(2);
    
    insert into table1 values(3);
    insert into table3 values(3);
    insert into table3 values(3);
    
    insert into table1 values(4);
    insert into table2 values(4);
    insert into table2 values(4);
    insert into table2 values(4);
    insert into table3 values(4);
    insert into table3 values(4);
    
    commit;
    
    with child1_cnt as
    (
      select par_row_id,count(*) cnt
      from table2
      group by par_row_id
    ),
    child2_cnt as
    (
      select par_row_id,count(*) cnt
      from table3
      group by par_row_id
    ),
    all_counts as
    (
      select p.row_id,nvl(c1.cnt,0) c1_cnt,nvl(c2.cnt,0) c2_cnt
      from table1 p
       left outer join child1_cnt c1
         on ( p.row_id = c1.par_row_id )
       left outer join child2_cnt c2
         on ( p.row_id = c2.par_row_id )
    )
    select row_id,c1_cnt,c2_cnt
    from all_counts
    where c1_cnt != c2_cnt;
    
    ROW_ID C1_CNT C2_CNT
    ------ ------ ------
         2      2      0
         4      3      2
         3      0      2 
    
  • Query should return the number of records that do not match the values of the DB

    I have the SQL query in the IN clause that I have certain values to verify each year against DB. I need a query that should tell the number 1 for existing records and 0 to not exist records. I get only matched lines from now account. Help is very appreciated.

    sample

    number of values
    SAM 1
    CAT 0
    POOL 1
    JACK 1
    FUN 0


    Concerning
    Prakash.
    with search_for_values as (
    select 'SAM' name from dual
    union all select 'CAT' from dual
    union all select 'HEN' from dual
    union all select 'JACK' from dual
    union all select 'FUN' from dual
    )
    , search_in_tab as (
    select 'SAM' name from dual
    union all select 'HEN' from dual
    union all select 'JACK' from dual
    union all select 'HEN' from dual
    union all select 'JACK' from dual
    union all select 'HEN' from dual
    union all select 'JACK' from dual
    )
    select sfv.name
         , case when exists ( select null from search_in_tab sit where sit.name = sfv.name  ) then 1 else 0 end   cnt
    from search_for_values sfv
    

    Anton

Maybe you are looking for

  • HP Pavilion-15 ab270sa: how to disassemble the laptop screen... ?

    How are you involved in a HP monitor on a laptop... ? I need to do maintenance on the webcam/mic handset. I have a HP Pavilion 15. HP Pavilion-15 ab270sa to be precise No obvious screws anywhere to disassemble.

  • Satellite L20-183 - battery will not charge

    For two days the Toshiba * Satellite L20-183 original * battery does not charge.The laptop * works on a/c * power, but its * battery is stuck * on 3%. You have an idea, what could be the problem?The laptop is almost three years, and the battery itsel

  • Envelope of DLX on HP8600

    I have a new HP8600 which, to this day, I was very satisfied. However, today, I had the need to print an envelope.  The envelope in question was size DLX, an Australian Post recommended size.  Unfortunately, it is not listed as a standard size in the

  • Another "this computer is not running genuine Windows.

    I started getting this pop up a week ago. Following some discussion here about it and ran MGADiag, as mentioned exe. Here is the report. Thanks for any help! Diagnostic report (1.9.0027.0):-----------------------------------------Validation of Window

  • Separate card for Inspiron 15R 5537 video

    Hi, I recently bought a Dell Inspiron 15r 5537 and I wanted to know if its possible to install a discrete videocard on this laptop. Appreciate any help.