我正在试图找出一个查询,其中显示了在2个以上部门工作的员工的姓名以及他们的工资和联系方式。我有两个表员工和部门。这两个都有EmployeeName字段。我知道我们必须使用Count函数,但不知道如何创建查询。
这里有tablename和Fields:
Employee
(employeeName,wage,contactNo)Department
(employeeName,departmentNo,hours,startDate)答案 0 :(得分:4)
您的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
答案 1 :(得分:1)
您可以使用以下查询:
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