MySQL查询、计数问题
谢谢大家 - 解决了!
我有以下代码:
SELECT region, division, SUM(staff_count) AS Total_Staff,
(SELECT COUNT(region) FROM tresults_xyc WHERE division = 'Central' GROUP BY region) AS Total_Responses
FROM `trespondent_xyc`
WHERE division = 'Central'
GROUP BY region
它返回以下内容:
region division Total_Staff Total_Responses
1 Central 212 8
2 Central 168 8
3 Central 164 8
4 Central 180 8
列区域、部门和 Total_Staff 中包含的信息是正确的。
但是,Total_Responses 列不是 - 它显示的是该部门而不是每个区域的响应总数。
有人可以建议吗?
预先感谢,
荷马。
THANKS EVERYONE - SOLVED!
I have the following code:
SELECT region, division, SUM(staff_count) AS Total_Staff,
(SELECT COUNT(region) FROM tresults_xyc WHERE division = 'Central' GROUP BY region) AS Total_Responses
FROM `trespondent_xyc`
WHERE division = 'Central'
GROUP BY region
It brings back the following:
region division Total_Staff Total_Responses
1 Central 212 8
2 Central 168 8
3 Central 164 8
4 Central 180 8
The information contained in the colomns region, division, and Total_Staff are correct.
However, the Total_Responses colomn is not - that is showing the total number of responses for the Division and not each region.
Can anyone advise?
Thanks in advance,
Homer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你必须这样做:
You have to do this :
尝试
try