我试图制作一个SQL语句,我可以看到哪个员工遵循了两个特定的课程。但我不确定如何在SQL中执行此操作。我有以下查询
SELECT cursist FROM inschrijvingen WHERE cursus IN ('XML', 'JAV');
Cursist是employeeID,inschrijvingen基本上是所有课程的注册。现在,这将返回所有已使用XML或JAVA的员工ID。我如何检查所有同时进入的员工?
谢谢!
答案 0 :(得分:3)
SELECT cursist
FROM inschrijvingen
WHERE cursus IN ('JAV')
AND cursist IN (
SELECT cursist
FROM inschrijvingen
WHERE cursus IN ('XML')
);
答案 1 :(得分:2)
这可能是使用Set运算符的另一种方式:
(SELECT cursist FROM inschrijvingen WHERE cursus='XML')
intersect
(SELECT cursist FROM inschrijvingen WHERE cursus='JAV');
答案 2 :(得分:1)
你很亲密。聚合完成了您的解决方案:
SELECT cursist
FROM inschrijvingen
WHERE cursus IN ('XML', 'JAV')
GROUP BY cursist
HAVING COUNT(*) = 2;
如果inschrijvingen
可能有重复项,则需要HAVING COUNT(DISTINCT cursus) = 2
。