SQL 获取未参与项目的姓名 [英] SQL get names who didnt work on a project
本文介绍了SQL 获取未参与项目的姓名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检索没有在 PostgreSQL 中参与项目的人员的姓名.
I would like to retrieve the names of people who didn't work on a project in PostgreSQL.
我有一个名为 employees
的表格,其中包含他们的 names
和 ssn
.
I got a table named employees
with their names
and ssn
.
我的第二个表名为 works_on
,包括 ssn
和 project_number
My second table is called works_on
and includes ssn
and project_number
ssn
这里是employees
现在我尝试了以下方法:
Now I tried the following:
SELECT fname,lname
FROM werknemer w
JOIN werkt_aan wa
ON (wa.ssn = w.ssn)
WHERE wa.ssn <> w.ssn
但这不会返回任何内容,但我需要 1 个不在单个项目上工作的名字.有人可以向我解释如何做到这一点吗?提前致谢.
But this returns nothing, but I need 1 name who is not working on a single project. Can someone explain to me how to do this? Thanks in advance.
推荐答案
这通常使用 NOT EXISTS
查询来解决:
This is usually solved using a NOT EXISTS
query:
select e.*
from employees e
where not exists (select *
from works_on wo
where wo.ssn = e.ssn)
这篇关于SQL 获取未参与项目的姓名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文