我需要 MySQL 查询方面的帮助
I have two tables - `employee` and `department`.
1. `employee` table contains column id,employee name and dept_id
2. `department` table contains column id, department name.
I need exact department name which contains
1. maximum employee and
2. no employee
编辑:
Apologizing for bad grammar, here is the example for above two questions what i need.
1. for eg: if two department contains same number of employees, i need to show both department not single by limit.
2. for eg: if more than one department contains 0 employees, i must show those departments particularly.
I have two tables - `employee` and `department`.
1. `employee` table contains column id,employee name and dept_id
2. `department` table contains column id, department name.
I need exact department name which contains
1. maximum employee and
2. no employee
Edited:
Apologizing for bad grammar, here is the example for above two questions what i need.
1. for eg: if two department contains same number of employees, i need to show both department not single by limit.
2. for eg: if more than one department contains 0 employees, i must show those departments particularly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为应该这样做。我有一段时间没有用 mysql 做任何事情了。
编辑:错过了第二个问题
i think that should do it. i've not done anything with mysql in a while.
edit: missed the second question
第一个问题的回答:
第二个问题的回答:
Answer to the first question:
Answer to the second question:
如果我没看错问题,你需要:
If I read the question right, you need:
这将为您提供按员工数量排序的部门排序列表。
要获取没有员工的部门,
请在 GROUP BY 之前添加:...。
要获取员工最多的部门,请在末尾添加
DESC LIMIT 1
。This will get you a sorted list of departments, sorted by number of employees.
To get departments with no employees, add:
...before the GROUP BY.
To get the department with the most employees, add
DESC LIMIT 1
to the end.显示包含最多员工的部门名称和员工数量的查询:
显示没有员工的部门的查询:
如果需要在一个查询中显示它,请粘贴第一个查询,添加 UNION ALL,然后粘贴第二个查询。
Query that shows department names with maximum employees and number of employees in it:
Query that shows departments with no employees:
If you need to show it in one query, paste first query, add UNION ALL and then paste second query.