-
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.
-
select cid, count(*) from(
select distinct cid, gid from thetablewhereyourddatais)
group by cid
order by cid;
-
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.
-
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.
-
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.
-
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
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|