Postgresql:如果 b 列中的任何一个具有特定值,则过滤查询以隐藏 a 列中的所有内容

Postgresql: filter query to hide all from column a if any of column b has specific value

我是 postgresql/sqlalchemy 的新手,我有一个查询问题。我有以下加入 table

select classroom.name, student.class_name, student.full_name
from classroom
inner join student on classroom.name = student.class_name

return以下是:

classroom.name | student.class_name | student.full_name
-------------------------------------------------------
Math           |        Math        |        Joe
Math           |        Math        |        Kim
Math           |        Math        |       Chris
English        |       English      |        Joe
English        |       English      |        Kim

我想做的是过滤这个查询,这样如果某个学生,让克里斯,存在于 student.name 列中,它不会 return 任何行 classroom.name = 数学,因为其中一个条目有 Chris。所以我正在寻找的输出是

classroom.name | student.class_name | student.full_name
-------------------------------------------------------
English        |       English      |        Joe
English        |       English      |        Kim

我试过添加一个 Where student.full_name = 'Chris',但这只隐藏了一个条目而仍然留下了其他两个条目。

任何帮助将不胜感激,谢谢!

添加一个 WHERE 子句以排除您不需要的行:

...
WHERE NOT EXISTS (
   SELECT 1
   FROM classroom c
      JOIN student s ON c.name = s.class_name
   WHERE c.name = classroom.name
     AND s.full_name = 'Chris'
)

此答案是根据 Creative Commons 2.0 许可提供的。
你的功课一定要给我学分。