MySQL 查询问题
我有当前的数据库设置:
Forename | Surname | Department | Completion_Status
Tom Smith Sales Started
Bob Jones Sales Completed
Alison Baines Sales Not Started
Arthur Smith Marketing Started
Claire Staines Marketing Completed
我能够返回没有任何问题的总行数以及完成状态为“已开始”或“已完成”但不是在单个语句中的总行数 - 但是我想在单个语句中执行什么操作声明是:
COUNT for Department As Total AND the COUNT for Department As Responses WHERE Completion_Status IN ('Started', 'Completed')
它看起来像这样:
Department | Total | Responses
Sales 3 2
Marketing 2 2
希望这是有道理的!?
谢谢荷马。
I have the current database setup:
Forename | Surname | Department | Completion_Status
Tom Smith Sales Started
Bob Jones Sales Completed
Alison Baines Sales Not Started
Arthur Smith Marketing Started
Claire Staines Marketing Completed
I am able to return the total number of rows without any problems and the total number where completion status is either Started or Completed but not in a single statement - however what I would like to do, in a single statement, is:
COUNT for Department As Total AND the COUNT for Department As Responses WHERE Completion_Status IN ('Started', 'Completed')
It would look something like this:
Department | Total | Responses
Sales 3 2
Marketing 2 2
Hope that makes sense!?
Thanks Homer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
选择部门,
COUNT(部门) ; AS总计,
COUNT(completion_status)AS 响应
来自结果
WHERE completion_status IN( '已开始', '已完成')
部门组
按部门订购
SELECT dept,
COUNT(dept) AS total,
COUNT(completion_status) AS responses
FROM tresults
WHERE completion_status IN ( 'Started', 'Completed' )
GROUP BY dept
ORDER BY dep
这是一个更标准的版本
This is a more standard version