0

嗨,我有以下 sql 语句,它为我提供了first_name每个员工一起完成的工作的总数和总数,但现在我想要一个员工first_namejob_id另一个工人一起做的工作,我总共有三个表

下面是我用来获取名字和工作总数的代码

SELECT first_name, COUNT(link.job_id) 
FROM employee, job, link 
WHERE  job.job_id = link.job_id 
AND employee.employee_id = link.employee_id 
GROUP BY first_name 
HAVING (COUNT(link.job_id) > 1 ) ;

有人可以帮忙吗

4

1 回答 1

2

这个怎么样:

SELECT first_name, COUNT(link.job_id) 
FROM employee, job, link 
WHERE  job.job_id = link.job_id 
AND employee.employee_id = link.employee_id
AND job.job_id IN (SELECT job_id FROM link GROUP BY job_id HAVING COUNT(*) > 1) 
GROUP BY first_name 
HAVING (COUNT(link.job_id) > 1 ) ;

子查询将获取涉及一名以上员工的所有工作。

于 2012-04-04T08:52:53.107 回答