我有以下查询:
SELECT mutations.id, genes.loc FROM mutations, genes where mutations.id=genes.id;
并输出以下内容:
| SL2.50ch02_51014904 | intergenic | | SL2.50ch02_51014907 | upstream | | SL2.50ch02_51014907 | downstream | | SL2.50ch02_51014907 | intergenic | | SL2.50ch02_51014911 | upstream | | SL2.50ch02_51014911 | downstream |
我想要的输出是这样的:
| SL2.50ch02_51014904 | intergenic | | SL2.50ch02_51014907 | upstream,downstream,intergenic | | SL2.50ch02_51014911 | upstream,downstream |
我认为GROUP_CONCAT这很有用。但是,这样做:
GROUP_CONCAT
SELECT mutations.id, GROUP_CONCAT(distinct(genes.loc)) FROM mutations, genes WHERE mutations.id=genes.id;
我有一个像这样的独特行:
SL2.50ch02_51014904 | downstream,intergenic,upstream
我该如何解决?
您需要添加group by:
group by
SELECT m.id, GROUP_CONCAT(distinct(g.loc)) FROM mutations m JOIN genes g ON m.id = g.id GROUP BY m.id;
在此过程中,您应该学到其他一些知识:
join
from
m
g