DBAsupport.com Forums - Powered by vBulletin
Results 1 to 6 of 6

Thread: query help

  1. #1
    Join Date
    Mar 2001
    Location
    south africa
    Posts
    401

    query help

    Hi

    customerid number(6)
    customertype char(1)


    we have two different customers types(P,A).Some are only one customer type but some have both types.

    customerid -- ctype
    ----------- -------
    123 -p
    234-A
    234-P
    345-A
    888-A

    how do i retreive only those who has both customertype values such as 234

    Thanks

  2. #2
    Join Date
    Jul 2002
    Location
    Lake Worth, FL
    Posts
    1,492

    Cool


    Maybe you could use the COUNT() function with the SELECT ... HAVING option.
    "The person who says it cannot be done should not interrupt the person doing it." --Chinese Proverb

  3. #3
    Join Date
    Mar 2001
    Location
    south africa
    Posts
    401
    i did , still wrong ,here is the query

    select cid, ctype, count(*) from cust
    and ctype in ( 'P', 'A') group by cid, ctype
    having ctype in ( 'P', 'A')

  4. #4
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    Code:
    SQL> select * from cust ;
    
            ID T
    ---------- -
           123 P
           234 A
           234 P
           345 A
           888 A
    
    SQL> get x1
      1  select a.id
      2  from cust a, cust b
      3  where a.id = b.id and
      4        a.type = 'A' and
      5*       b.type = 'P'
    SQL> /
    
            ID
    ----------
           234
    Tamil

  5. #5
    Join Date
    Jun 2005
    Location
    London, UK
    Posts
    159
    Quote Originally Posted by prodadmin
    i did , still wrong ,here is the query

    select cid, ctype, count(*) from cust
    and ctype in ( 'P', 'A') group by cid, ctype
    having ctype in ( 'P', 'A')
    LKB was probably thinking of something more like:

    Code:
    SQL> select * from c;
    
    CUSTOMERID C
    ---------- -
           123 P
           234 A
           234 P
           345 A
           888 A
    
    5 rows selected.
    
    SQL> SELECT customerid, COUNT(*)
      2  FROM   c
      3  GROUP BY customerid
      4  HAVING MIN(customertype) <> MAX(customertype);
    
    CUSTOMERID   COUNT(*)
    ---------- ----------
           234          2
    
    1 row selected.

  6. #6
    Join Date
    Mar 2001
    Location
    south africa
    Posts
    401
    thanks , both works for me .much appreciated

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width