我如何只提取缺少所有电子邮件条目的记录

how do i extract only the records with all email entries missing

我有一个问题所以我有这个 table:

| Manager_Name | Email_Address |
| ------------ | ------------- |
| person A     |Email@email.com|
| person A     |Null|
| person A     |Null|
| person A     |Email@email.com|
| person A     |Email@email.com|
| person B     |Null|
| person B     |Null|
| person B     |Null|
| person B     |Null|
| person B     |Null|
| person C     |Email@email.com|
| person C     |Email@email.com|
| person C     |Email@email.com|
| person C     |Email@email.com|
| person C     |Email@email.com|
| person D     |Null|
| person D     |Null|
| person D     |Null|
| person D     |Null|
| person D     |Null|

我的问题是如何只提取缺少所有 5 个电子邮件地址的经理,例如 B 人和 D 人,在原来的 table 我有很多我只想得到他们缺少所有 5 个地址。

可以按Manager_Name分组,在HAVING子句中设置条件:

SELECT Manager_Name
FROM tablename
GROUP BY Manager_Name
HAVING MAX(Email_Address) IS NULL;

参见demo

您可以这样使用 NOT EXISTS

SELECT * FROM table a WHERE NOT EXISTS(
    SELECT 1 FROM table b 
    WHERE a.Manager_Name = b.Manager_Name AND Email_Address IS NOT NULL
)