oracle 使用 SQL 查询获取在多个部门工作的员工

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15739396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:32:54  来源:igfitidea点击:

Get employees who worked in more than one department with SQL query

sqloraclecountjointable

提问by GoldFish

I'm trying to figure out a query which shows the names of the employees who worked in more than 2 departments along with their wage and contact details. I have two tables employees and department. Both of these having the EmployeeName field. I know we have to use the Count function but don't really know how to create the query.

我试图找出一个查询,该查询显示在 2 个以上部门工作的员工的姓名以及他们的工资和联系方式。我有两张表员工和部门。这两个都有 EmployeeName 字段。我知道我们必须使用 Count 函数,但真的不知道如何创建查询。

here the tablename and Fields:

这里是表名和字段:

  • Employee(employeeName, wage, contactNo)
  • Department(employeeName, departmentNo, hours, startDate)
  • Employee(员工姓名、工资、联系人编号)
  • Department(员工姓名、部门编号、工作时间、开始日期)

回答by Alex

You SQL query would be the following

您的 SQL 查询如下

  SELECT e.employeeName, count(departmentNo) FROM Employee e 
  INNER JOIN Department d ON e.employeeName=d.employeeName 
  GROUP BY e.employeeName 
  HAVING COUNT(departmentNo)>2

回答by apps

you can use following query:

您可以使用以下查询:

SELECT e.employeeName, count(d.departmentname) 
FROM Employee e, Department d  
where e.deptid=d.deptid 
GROUP BY e.employeeName 
HAVING COUNT(e.deptid)>=2