This question is an exact duplicate of:
这个问题与以下内容完全相同:
- Select using joins [closed] 1 answer
选择使用连接[关闭] 1个答案
Lets say I have 2 tables, 1 table the teams and another table a record of which player belongs to what team.
让我们说我有2个桌子,1个桌子和另一个桌子记录哪个球员属于哪个球队。
I need the result of the select to show me how many players are per team. as you see in the picture.
我需要选择的结果向我展示每队有多少球员。正如你在图片中看到的那样。
Thanks for the help
谢谢您的帮助
1 个解决方案
#1
1
Use a JOIN and GROUP BY.
使用JOIN和GROUP BY。
http://sqlfiddle.com/#!9/5b7f0/1
SELECT
t.name, COUNT(*) AS `#players`
FROM Teams t INNER JOIN Player_perteam p ON t.id = p.idteam
GROUP BY t.name
#1
1
Use a JOIN and GROUP BY.
使用JOIN和GROUP BY。
http://sqlfiddle.com/#!9/5b7f0/1
SELECT
t.name, COUNT(*) AS `#players`
FROM Teams t INNER JOIN Player_perteam p ON t.id = p.idteam
GROUP BY t.name