SQL Query
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 7 of 7

Thread: SQL Query

  1. #1
    Join Date
    Jul 2001
    Posts
    334

    SQL Query

    All,
    There is a table with gene_ids ('gid') and clone_ids ('cid'). Each gene only resides on a single clone and each clone may contain multiple genes. How do you find how many genes are on each and every clone? Please provide the SQL.

    Thanks in advance.

  2. #2
    Join Date
    Nov 2000
    Location
    Pittsburgh, PA
    Posts
    3,966
    select cid, count(*) from(
    select distinct cid, gid from thetablewhereyourddatais)
    group by cid
    order by cid;
    this space intentionally left blank

  3. #3
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,554
    I probably missed something but at first glance I would do...
    Code:
    select   cid         "Clones", 
             count(*)    "Genes"
    from     thetablewhereyourddatais
    group by cid
    order by cid;
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  4. #4
    Join Date
    Nov 2000
    Location
    Pittsburgh, PA
    Posts
    3,966
    Quote Originally Posted by PAVB
    I probably missed something but at first glance I would do...
    Code:
    select   cid         "Clones", 
             count(*)    "Genes"
    from     thetablewhereyourddatais
    group by cid
    order by cid;
    As long as the cid, gid columns are unique in the table where aph is running the query, then your answer is correct. I just wrote it so that it would not matter if they were unique or not.
    this space intentionally left blank

  5. #5
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,554
    Quote Originally Posted by gandolf989
    As long as the cid, gid columns are unique in the table where aph is running the query, then your answer is correct. I just wrote it so that it would not matter if they were unique or not.
    Reading poster's specs about "Each gene only resides on a single clone..." I supposed data was compliant with the specs. I've to agree if data is a mess your solution might show a closer solution.
    Last edited by PAVB; 05-19-2008 at 02:50 PM.
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  6. #6
    Join Date
    Jul 2002
    Location
    Lake Worth, FL
    Posts
    1,440

    Wink

    And...you gave him the fish instead of teaching him how to fish!
    "The person who says it cannot be done should not interrupt the person doing it." --Chinese Proverb

  7. #7
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,554
    Quote Originally Posted by LKBrwn_DBA
    And...you gave him the fish instead of teaching him how to fish!
    Not my fault, when I got there the guy was already eating a proper Fish and Chips with mushy peas
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

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