开发者

MySql : Group rows my multiple columns and return the count

开发者 https://www.devze.com 2023-01-04 22:11 出处:网络
I have a MySql table having the following structure: ontology_term pathway_id pathway_name I want to write a query using which we can get mapping between various pathways (having unique id\'s -> pa

I have a MySql table having the following structure:

ontology_term
pathway_id
pathway_name

I want to write a query using which we can get mapping between various pathways (having unique id's -> pathway_id) based on the number of common ontology terms.

So the output should be,

Pathway_id1, Pathway_id2, No. of common terms

I know, it can be easily done using a server side l开发者_运维知识库anguage, will it be faster to use MySql instead?


If I understood you right, that is

select a.pathway_id, b.pathway_id, count(*)
from t a
inner join t b on a.ontology_term = b.ontology_term
group by a.pathway_id, b.pathway_id

There is no record if two pathways do not have common terms

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号