[英]MySQL & PHP: Joins & Counts
I want to select all users from my table where access_level_id!=0. 我想从我的表中选择所有用户,其中access_level_id!= 0。 I also want to count the number of entries in another table where the user id matches a field (this could be 0 or 100).
我还想统计用户ID与字段匹配的另一个表中的条目数(可以为0或100)。
I have: 我有:
SELECT users.id, count(clients.id) as count FROM $db[users] as users
LEFT JOIN $db[clients] as clients ON users.id=clients.salesrep_id
WHERE users.access_level_id!='0'
This is returning just a single number (17) 这仅返回一个数字(17)
You have to group the results. 您必须将结果分组。 Try adding
GROUP BY users.id
to your Query. 尝试将
GROUP BY users.id
添加到查询中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.