表1包括员工姓名及其姓名缩写 表2包括projectnumber和pmember(也是首字母)
我们只需要显示员工的名字,所以我必须使用WHERE子句,我无法构建:(这是我到目前为止所做的。它只返回1名员工(正确答案是2名员工) )
select t1.name
from t1
where t1.initials IN (select t2.pmember
from t2
having count(t2.projectnumber) > 1)
提前谢谢!
答案 0 :(得分:0)
要显示适用于所有项目的所有emp,您需要这样的独特计数,我认为:
SELECT NAME FROM T1 WHERE INITIALS IN (
SELECT PMEMBER FROM T2 HAVING DISTINCT COUNT(PROJECTNUMBER) = (
SELECT DISTINCT COUNT(PROJECTNUMBER) FROM T2)
GROUP BY PMEMBER)
答案 1 :(得分:0)
select t1.name
from t1
left join t2 on t1.initials = t2.pmember
group by t1.name
having sum(t2.projectnumber is null) = 0
答案 2 :(得分:0)
此查询应该为您提供处理所有项目的成员的名称:
SELECT T1.NAME
FROM T1
JOIN T2 ON T1.INITIALS = T2.PMEMBER
GROUP BY T1.NAME
HAVING COUNT(T2.PROJECTNUMBER) = (SELECT COUNT(1) FROM T2 T2ALIAS)
答案 3 :(得分:0)
也许此查询可以帮助您:
SELECT T1.NAME
FROM T1
INNER JOIN T2 ON T1.INITIALS = T2.PMEMBER
HAVING COUNT(T2.PROJECTNUMBER) > 1