mysql 在第三个 table 中加入计数行
mysql join count lines in third table
我有三个这样的 mySQL-表:
client network activities
\_id \_id \_id
\_name \_name \_client_id
\_[...] \[...] \_[...]
\_network_id
现在我想要得到以下结果:
client.*, network.name, number_of_activities_for_each_client
实际上我有这个select-声明:
select client.*, network.name
from client
left join network
on client.network_id = network.id
如何扩展语句?我也想见见所有客户
SELECT c.*, n.name, COUNT(a.id) number_of_activities_for_each_client
FROM clients c
LEFT JOIN network n
ON n.id = c.network_id
LEFT JOIN activities a
ON a.client_id = c.id
GROUP BY c.id
我有三个这样的 mySQL-表:
client network activities
\_id \_id \_id
\_name \_name \_client_id
\_[...] \[...] \_[...]
\_network_id
现在我想要得到以下结果:
client.*, network.name, number_of_activities_for_each_client
实际上我有这个select-声明:
select client.*, network.name
from client
left join network
on client.network_id = network.id
如何扩展语句?我也想见见所有客户
SELECT c.*, n.name, COUNT(a.id) number_of_activities_for_each_client
FROM clients c
LEFT JOIN network n
ON n.id = c.network_id
LEFT JOIN activities a
ON a.client_id = c.id
GROUP BY c.id