简体   繁体   English

如何在 MySQL 中正确使用 INNER JOIN?

[英]How to use INNER JOIN correctly in MySQL?

I get a syntax error in this SQL query below, where it tells me INNER JOIN is not correctly used.我在下面的 SQL 查询中收到语法错误,它告诉我 INNER JOIN 未正确使用。 How can I solve this?我该如何解决这个问题? Thanks!谢谢!

select m1.player, count(distinct m1.species) 
from phonemon as m1
group by player
INNER JOIN 
select ti.title, count(*)
from type as t1, species as s1
where s1.type1 = t1.id or s1.type2 = t1.id
group by t1.title

I join phonemon to species by type1 or type2 equaling id.我通过等于 id 的 type1 或 type2 将 phonemon 加入到物种中。 I group by player and sort by title.我按玩家分组并按标题排序。

select m1.player, count(distinct m1.species) SpeciesCount from phonemon as m1
join species s1
    on s1.type1=t1.id or s1.type2=t1.id
group by
m1.player
order by t1.title

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM